Close Window Automatically After Printing Dialog Closes

go to previous window automatically after printing dialog closes

Use this to go back to previous page

$(document).ready(function() {
window.print();
history.go(-1);
});

or:

$(document).ready(function() {
window.print();
history.back();
});

Closing a tab with javascript after printing from a web page

In my case, I want to open a new tab, which contains a script that automatically triggers the browser's print dialog. Once the print dialog is dismissed, I want the new tab to go away. Since the scripts in the new page were not what created that page, they don't have the ability to close it.

So from what I can understand is that you have a script in the new tab which triggers a dialog and once this dialog is dismissed you want to close that tab.

assuming you have control over the dialog dismissed event you can close this window using window.close(); in dialog dismissed event handler which is written within this newly opened tab.

And commenting on this statement

Since the scripts in the new page were not what created that page, they don't have the ability to close it.

yes you are right, But you can close the current tab from the scripts within this current tab. And that's when window.close(); is used. which closes the current window.

Hope this is helpful.

Problem: Jquery printing close window immediately after open

I've worked around it with iFrame

The iFrame:

 <iframe id="print_this_iframe" hidden></iframe>

The Jquery:

var dstFrame = document.getElementById('print_this_iframe');
var dstDoc = dstFrame.contentDocument || dstFrame.contentWindow.document;
dstDoc.write('Some Content');
dstDoc.close();
dstFrame.onload = function() { $("#print_this_iframe").get(0).contentWindow.print()};

window.close(); after window.print(); javascript

<a href="javascript:;" onclick="print()">Print</a>

function print()
{
win = window.open();
win.document.write('<html><head>blablabla.......');

var document_focus = false; // var we use to monitor document focused status.
// Now our event handlers.
$(document).ready(function() { win.window.print();document_focus = true; });
setInterval(function() { if (document_focus === true) { win.window.close(); } }, 300);
}

Thanks Stilltorik for link.



Related Topics



Leave a reply



Submit