0

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. 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

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

1 Answer 1

1

I found the solution. Chrome needs a time delay to do this job. So here is update

fisBas.php Js Code

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

window.open call

window.open(BASE_URL + "fisBas?sale_id=" + data.lastInsertId + "&sale_type=" + data.sale_type + "", "_blank");
setTimeout(function(){
   location.reload();
}, 1000);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.