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
How to Show Roles of User Discord.Js/Userinfo Command
How to Find Object in a List of Items by Index Using Es6 (Reactjs)
How to Programmatically Clear/Reset React-Select
Select Value of Input Element Inside HTML Table Using Jquery
How to Pass 3 Parameters in Onclick Function .The Parameters Are Inside PHP Tag
Require(Img Path) Not Working/ Cannot Find Module "." Reactjs
Scroll to Element from Typescript Code (Angular 5)
Stylesheet Not Loading Because Mime Type Is Text/Html
Changing the Browser Zoom Level
How Add a New Key/Value Pair to a Json Object
Browserify :- Uncaught Typeerror: Fs.Readfilesync Is Not a Function
How to Unit Test If an Element Is Visible When the *Ngif Directive Is Used Using Jasmine in Angular
How to Set Image to Fit Width of the Page Using Jspdf
How to Replace Double/Multiple Slash to Single in Url
How to Get Only 1St Element of Json Data
How to Refresh Form Page After Post Request
How to Style HTML Select Option Hover and Selected Option Effects