简体   繁体   English

跨浏览器javascript window.open方法

[英]Cross Browser javascript window.open method

Hi i am currently working on a web app. 嗨,我目前正在使用网络应用程序。 I have to open a popup and print the page. 我必须打开一个弹出窗口并打印页面。 After page printing process popup must be closed. 页面打印过程结束后,必须关闭弹出窗口。 In firefox everything its good but when it comes to Chrome its not working. 在firefox中,一切都很好,但在Chrome上却无法正常工作。 it print empty page. 它打印空白页。 Here is the code. 这是代码。

$.ajax({
    type: "POST",
    url:  BASE_URL + "blabalba.php",
    data: dataString,
    success: function(res){

        var data = JSON.parse(res);
        if(data.status == 1){
            window.open(BASE_URL + "fisBas?sale_id=" + data.lastInsertId + "&sale_type=" + data.sale_type + "", "_blank");
            location.reload();
        }
        else 
            swal(data.message, "", "error");

    },

    error: function(){
        swal("xxxx", "", "error");
    }

FisBas.php js code FisBas.php js代码

$(function(){
  window.print();
  window.close(); 
 // this code works on firefox.
)};

I found the solution. 我找到了解决方案。 Chrome needs a time delay to do this job. Chrome需要一段时间才能完成此工作。 So here is update 所以这是更新

fisBas.php Js Code fisBas.php Js代码

    $(function(){
      window.print();
      setTimeout(function(){
        window.close();
      }, 1000)
    })

window.open call window.open调用

window.open(BASE_URL + "fisBas?sale_id=" + data.lastInsertId + "&sale_type=" + data.sale_type + "", "_blank");
setTimeout(function(){
   location.reload();
}, 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM