Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if onclick else onunload function??

Status
Not open for further replies.

venomdesign

Programmer
Apr 6, 2001
18
0
0
US
Does anyone know how to script something that in a pop-up window before they can close the window they need to print the page. For example, you go to a page and you are required to print the page, so if you click the print button within the page it prints then closes the window, but if they do not click the print button and leave the page or close the window an onunload function comes up and alerts them they need to print the page before it will close and won't close unless they press the print button.
 
try this but i'm not too certain about it:

<html>

<head>
<script>
Code:
function myMsg(){

if(window.print())
{
alert(&quot;Thank you&quot;)
}else{

alert(&quot;Please print page&quot;)
  location.reload()
  }
}
</script>

<body onUnload=&quot;myMsg()&quot;>

</body>
</html>
 
can't you just print the page on both situations? i mean when a user have to print the page make the onunload event print it out. This would make the need for a print button unnecessary, and would lessen confusion otherwise set a global variable within that page that has a certain value when the print button is click. hope this helps. and i think bench is right im not so sure about the
Code:
window.print()
function either.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top