faqts : Computers : Programming : Languages : JavaScript : Event handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 37 people (57%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I stop a body ONBLUR="window.close();" affecting onClick="javascript:window.print()

Sep 11th, 2002 02:55
Jean-Bernard Valentaten, Nick Hearn,


I'd use a flag indicating whether the window has really lost it's focus 
or will get it back soon.
at the beginning of the document you write this inside a script-block:
var isPrinting = false;
in the body-tag you write:
onBlur="if (!isPrinting) window.close();"
onFocus="isPrinting = false;"
and finally in your link (or where ever):
onClick="isPrinting = true; window.print();"
HTH,
Jean