This is what I want to do:
- User clicks print button;
- This calls function, which does ajax call to get the text to be printed;
- A new window is opened and the text is written to this.
The window and print is handled like this:
my_text = "hello";
newWin= window.open();
newWin.document.write(my_text);
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
This works fine. My issue is how to get my_text
. I have tried to put the above code inside an ajax call:
$.ajax({
type: "GET", url: the_url, data: {},
success: function(data){
newWin= window.open();
newWin.document.write(data);
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
}
,error: function() {
}
});
However, this causes the new window to be seen as a pop-up and it's caught by the pop-up blocker. If I choose to see the pop-up message then it has correctly filled in the text. I tried opening the window first, but then nothing gets written to it.