View Full Version : Need help with popup onunload event

06-22-2005, 07:38 PM

I saw lot of good posts on this forum and i hope someone will also help me out in my prob :( here is what i want to do

When a user opens a page and try to close the page or got other page without clicking on a link then a popup should appear and page will not close until the popup is closed.

Please please i really need solution.

Thanx in advance

06-22-2005, 09:10 PM
It depends upon what you mean by a pop-up. The simplest is the alert box. Using that to fulfill your requirements as I understand them could be done something like this:
<title>Test Condition - Demo</title>
<script type="text/javascript">
var go
function checker(){
if (go!=='OK'){
alert('Please Click Required Link')
<body onunload="checker()">
<noscript><p>Javascript required to go forward from here, use your browser's 'Back' button if you do not wish to proceed.</p></noscript>
Required Link: <a href="#" onclick="go='OK';return false;">Click Here to Certify that You are Willing to View more content on this site</a><br>
<a href="#" onclick="location.href='cool.htm';return false;">Optional link to Cool Stuff</a><br>
<script type="text/javascript">
document.write('<a href="javascript:history.go(-1)" onclick="go=\'OK\';return true;">Click here to Go Back, you chicken?</a>');
</html>There are many other ways.