Forum Moderators: open

Message Too Old, No Replies

window.close, print preview and IE6

window.close, print preview and IE6

         

cerapier

1:02 am on Mar 14, 2003 (gmt 0)



I'm experiencing a little problem with the window.close() function in javascript.

I got some pages that report data to the user. I provide them with a 'printer friendly' link that opens a new window and displays the page w/o fancy formatting. This new window has a anchor tag that gives the user an easy way to close the window...

<a href="javascript:" onClick="window.close();">Close Window</a>

It works fine, unless you decide to do IE's print preview function. After returning to the window (from the preview viewing) the link does nothing.

This behavior isn't the same in Mozilla 1.2.1. Mozilla works exactly like I expected it to, w/ or w/o 'print preview'.

Anybody else experienced this or know how to handle it?

Thanks.
Calvin Rapier

tedster

5:17 am on Mar 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, cerapier.

The Explorer Print Preview function messes with lots of things, and it's near impossible to debug when errors start showing up with good code.

Try writing the link like this - it just might make a difference:

<a href="javascript:closeWindow()">Close Window</a>

cerapier

3:46 pm on Mar 14, 2003 (gmt 0)



Thanks, tedster.
I'd tried that format for the anchor as well, but had the same results.

What you said got me thinking though. Since the print preview comes up in a different window, maybe the browser was getting confused as to which window it is supposed to close.

Probably flawed logic, but I changed the code to
<a href="javascript:this.window.close()">Close Window</a>

and now it works both before and after viewing the print preview in all my browsers.