PDA

View Full Version : new window if exit from the site


muchi_us
02-04-2003, 05:28 PM
I try to do the follow : If the visitor exit my website (not change a page, definitly exits the site http://www.lasvegasmap.info) it should open a new window with another website (like www.google.com).

I found this script, but it doesn't work :

<head>
<SCRIPT language=javascript>
<!--
var exit=true;
function xit(){
if (exit){
open("http://www.google.com","_blank");
}
}
//-->
</SCRIPT>
</head>

<body onunload=xit()><A onclick=exit=false href="http://www.lasvegasmap.info/"></A>
</body>

Thank you for your help
Markus

requestcode
02-04-2003, 06:51 PM
To do that with a link and without javascript you could use the target property like this:
<A href="http://www.lasvegasmap.info/" TARGET="_blank">Click Me</A>

cg9com
02-04-2003, 07:06 PM
In your <head></head>

<script type="text/javascript">
function wopen() {
window.open('page.html');
}
</script>


<body onunload="wopen()">

arnyinc
02-04-2003, 07:48 PM
The code you originally posted works (unless I missed a typo), but you just have to use it correctly. You have to use onunload to trigger the popup window when someone is leaving a page. But you have to use it with that xit() function to withhold the popup if the user clicked a link on your site. This creates a lot of administrative overhead since you have to put onclick="exit=false" in every link that you don't want to trigger the popup, but you probably deserve it for forcing popups on your users anyway. :)


<html>
<head>
<SCRIPT language=javascript>
<!--
var exit=true;
function xit(){
if (exit)
window.open("http://www.google.com","_blank");
}
//-->
</SCRIPT>
</head>

<body onunload=xit()>
<A onclick="exit=false" href="http://www.lasvegasmap.info/page1.html">A link on your site</A>
<A onclick="exit=false" href="http://www.lasvegasmap.info/page2.html">Another link on your site</A>
<A href="http://www.codingforums.com/">A link on another site</A>
</body>
</html>


edit: this will popup the window if the user clicks a link that is not on your site or if they close their browser window.

muchi_us
02-05-2003, 12:42 AM
Originally posted by requestcode
To do that with a link and without javascript you could use the target property like this:
<A href="http://www.lasvegasmap.info/" TARGET="_blank">Click Me</A>

Thank you for your help I found the solution !

muchi_us
02-05-2003, 12:44 AM
Originally posted by cg9com
In your <head></head>

<script type="text/javascript">
function wopen() {
window.open('page.html');
}
</script>


<body onunload="wopen()">

Thank you for your help, I found the solution.