Hello, Maybe someone can help me out. I'm trying to create a sort of promt box that appears when people try to leave a site and ask them again if they really want to do that. I've found this script: <html> <body onbeforeunload="handleUnload();"> <a href="domain.com">Click Here</a> <script> function handleUnload() { event.returnValue = "Are You Sure You Wanna Leave"; } </script> </body> </html> HTML: This works. However, when I click the link, that warning apears too. There is a sort of solution: Add this: onClick="handleUnload=false" HTML: to every link on the site. So the whole little script looks like this: <html> <body onbeforeunload="handleUnload();"> <a href="domain.com" onClick="handleUnload=false">Click Here</a> <script> function handleUnload() { event.returnValue = "Are You Sure You Wanna Leave"; } </script> </body> </html> HTML: This works, but the problem is that I have to add that code into every single link on asite. Please, tell me is it possible to make that the box wouldn't appear when people click the link by not putting that snippet of code into every single link? Maybe it;s possible to insert sort of function or smth in the script itself so it could prevent the the box from appearing when people click on any link. Or maybe it's possible to include JS line into external CSS, so all the links would ignore the JS script? Could you advice anything? Thanx.
Things like these typically never work well. You can try investigating the event variable in your handler, perhaps there's a way to get referrer information or some other indication that the user is following a link on your site. I wouldn't bother with this to begin with, though, even if you do get it working right in all browsers, all it'd do is annoy the visitor.
Thanx. I've tried to research, but it's hard to find anything. Anyway, I'll just use the method for inserting code into links and see if it works.