Forum Moderators: open

Message Too Old, No Replies

A simple exit popup

is there a way...

         

stcrim

1:59 am on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a simple way to do an exit pop-up without having to do an onunload event in the body tag?

I want to use a .js file and keep all of the script off the page. The goal is to not have to add anything to the <body> tag.

Or - can this code be modified to provide an exit pop-up?

</SCRIPT>
<script language="JavaScript">
function mywin2() {
var W1028639942 = window.open('http://www.mysite.com/2nd/myfolder/index.html','winin2');
self.focus();
}
setTimeout("mywin2()",0000);
// -->
</script>

-s-

Hobgoblin

8:21 am on May 6, 2003 (gmt 0)

10+ Year Member



Why don't you want anything else in the body tag? That sounds an awful lot like ordering a cheeseburger and asking them to hold the cheese... :)

To include the JS as an external file, copy the entire script less the <script> tags and name the file whatever you like. I usually keep my scripts in a separate directory. Reference them like so in the <head> section:

<sript src="scipts/exitpop.js" language="JavaScript"></script>

Any linked JS files will load into the cache, so the functions will be available when needed.

To popup a window on an unload:

<body onUnload="unloadWin(); somethingElseIfNeeded();">

RonPK

10:36 am on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



stcrim, maybe you could use the attachEvent() method to attach an onUnload event to the body element.
Ofcourse the body element has to exist before anything can be attached to it, so you should not put the script call in the head of your document.

Proper browsers can be set to block such popups, so I guess it's no problem that this method is IE-only ;)

Check [msdn.microsoft.com ] for documentation.

ShawnR

11:22 am on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As you probably know, the timer solution won't work - the timer and its handler would be destroyed when the window is destroyed. Any means to do it that way would constitute a security hole in the browser and operating system (not saying security holes aren't there...).

One way to achieve something similar to what I think you are trying to achive would be a pop-under, activated by <snip>. Not that I am advocating such practice, mind you.

Shawn

moonbiter

4:41 pm on May 6, 2003 (gmt 0)

10+ Year Member



In addition to the attachEvent() method (which has some cross-browser problems), you can use the traditional way and attach the onunload event directly:


document.body.onunload = myfunction // attach onunload event

Note the lack of parenthesis on the function -- you are not calling the function, but just setting a reference to the event.

More info [xs4all.nl].