Today i added print functionality to a web page that basically changes the stylesheet for print formatting and also automatically fires the print dialogue for the user. On doing this in IE7 you get the message:
"The web page you are viewing is trying to close the window"
when running the follwing javascript added to the page on page load:
If Not ClientScript.IsStartupScriptRegistered(Me.GetType, "OnLoad") Then
ClientScript.RegisterStartupScript(Me.GetType, "OnLoad", "window.print();window.close();", True)
End If
All you need to do to counteract this is put the following javascript code in before the close:
window.open('','_self');
So the code will now look like this:
ClientScript.RegisterStartupScript(Me.GetType, "OnLoad", "window.print();window.open('','_self');window.close();", True)
Works a treat.
Wednesday 21 November 2007
The web page you are viewing is trying to close the window
Posted by Omen at 10:08
Labels: ASP.NET, IE, JAVASCRIPT
Subscribe to:
Post Comments (Atom)
15 comments:
Great work
Only from this place i found this solution.
Thank you verymuch.
Gayan Krishantha
(krishanthaene@gmail.com)
Great work
Only from this place i found this solution.
Thank you verymuch.
Gayan Krishantha
(krishanthaene@gmail.com)
Works perfectly well for me.
Thank you very much.
Take care.
Worked for me, too (IE8). Thank you very much!
MikeN
Works perfectly! Other pages had solutions to this which didn't work for me.
ROL
Awesome. it worked great. Thanks.
Hi, I have IE8 and I get access denied on the window.open('','_self','');
I tried also window.opener=self or other strings but then in this case I still get the popup message before it closes...
Any idea what might be wrong? Thanks
Excellent Work.
Thank you soo much...
This is the only place i found the solution for this.
Thanks & Regards.
P.Shiva Krishna
Excellent Work.
This the only place i found solution for this.
Thank you soo much..
Regards..
P.Shiva Krishna
This worked perfectly. I wish this showed up first in a Google search. Thank you so very much!
If I'm understanding this correctly, the window is essentially taking control of itself before closing, thus suppressing the silly popup.
Also @Christian
You said you get access denied on window.open('','_self',''); but I don't think we're calling it with a third parameter. Try just window.open('','_self');
Well done, Great work. Thanks
Hi dear!
Amazing wok.
I realy found it at this page
It works fine.
Thanks
Qaiser yaqoob
Fantastic. Thanks very much!
Works beautifully!, thanks for sharing!
Perfect! Worked like a charm. Thanks!
Post a Comment