首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >重新加载页面后打开新选项卡

重新加载页面后打开新选项卡
EN

Stack Overflow用户
提问于 2019-02-01 10:16:25
回答 2查看 74关注 0票数 0

我在打开新标签页时遇到问题。假设我在datatable上列出了一堆条形码,我必须选择需要扫描或创建pdf。我选择后,我按下按钮打开新的标签(创建pdf)。但我的问题是,它不是打开新的标签,只是在当前页面上重新加载页面。下面是我的代码

代码语言:javascript
运行
复制
$('#btnscanbar').on('click', function() {
            var cekdata = $(this).attr('data-cek');
            var judul = $(this).attr('data-target');
            var target2 = $('#btnsearch').attr('data-target');
            var dataString = "judul=" + cekdata;        
            var fFactory = $("#fFactory").val();
            var fmachine = $("#fmachine").val();
            var fbrand = $("#fbrand").val();
            $.ajax
            ({
                type: "post",
                url:  host+ "AMS/ajax",
                data: dataString,
                dataType: 'json',
                cache: false,
                success: function(json_data)
                {
                    if(json_data.total==0)
                    {
                        swal("Please select barcode wanna scan", "warning");
                    }
                    else
                    {


                        window.open(url+'pdf?judul=' + judul + '&fFactory=' + fFactory +'&fmachine=' + fmachine +'&fbrand=' + fbrand, '_blank')                     
                        //reload current page
                        location.reload();
                    }
                }
            });
        });

有什么解决方案吗?我需要打开新的标签和重新加载页面,但不与该代码一起工作。

更新:我找到了解决方案,我在打开新标签之前使用了alert,这里是我正在使用的代码

代码语言:javascript
运行
复制
swal({ 
                            title: "Ready for Scan",
                            text: "Your Barcode succesed being scan, press OK to see",
                            type: "success",
                            confirmButtonText: "Ok",
                        }).then(function(){ 
                            window.open(url+'pdf?judul=' + judul + '&fFactory=' + fFactory +'&fmachine=' + fmachine +'&fbrand=' + fbrand, '_blank')                     
                            window.location.reload();
                        });         
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-01 12:35:12

在这个问题上找到了解决方案

在这些代码上

代码语言:javascript
运行
复制
 window.open(url+'pdf?judul=' + judul + '&fFactory=' + fFactory +'&fmachine=' + fmachine +'&fbrand=' + fbrand, '_blank')                     
                    //reload current page
                    location.reload();

我变成了

代码语言:javascript
运行
复制
swal({ 
                            title: "Ready for Scan",
                            text: "Your Barcode succesed being scan, press OK to see",
                            type: "success",
                            confirmButtonText: "Ok",
                        }).then(function(){ 
                            window.open(url+'pdf?judul=' + judul + '&fFactory=' + fFactory +'&fmachine=' + fmachine +'&fbrand=' + fbrand, '_blank')                     
                            window.location.reload();
                        });    

它工作得很好,希望如果有人像我一样遇到问题,可以使用这些代码。:)

票数 0
EN

Stack Overflow用户

发布于 2019-02-01 12:08:31

这是我的解决方案。你可以参考它。希望能帮上忙,我的朋友:)

代码语言:javascript
运行
复制
<body>
    <form id="myForm">
      <div class="form-group">
        <label for="exampleInputEmail1">Email address</label>
        <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
        <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">Password</label>
        <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
      </div>
      <div class="form-group form-check">
        <input type="checkbox" class="form-check-input" id="exampleCheck1">
        <label class="form-check-label" for="exampleCheck1">Check me out</label>
      </div>
      <button onclick="myFunction()">Try it</button>
    </form>
 </body>   

<script>
    function myFunction() {
       //for open a new tab
       let win =  window.open("https://www.w3schools.com", "_blank");
       win.focus();
       //document.getElementById("myForm").reset();            
       location.reload(true); //Reloads the current page from the server 
    }   
</script>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54471969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档