Click to See Complete Forum and Search --> : When User leaves open Pop-Up and Run a Function!


tomyknoker
06-24-2003, 10:46 PM
Hi All,
I have this code that at the moment when the user clicks "Next Page" it loads the next page and also runs a function. How would I change this code so that when the user leaves the page or types in another email addresss, the function then runs and pops-up "nextpage.htm" in a new page,
thanks agin,
tom

<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!-- Begin

function goto_nextpage(){
thetime = new Date();
document.location="nextpage.htm?page_load="+page_load+"&button_1="+button_1+"&button_2="+button_2+"&button_3="+button_3+"&page_leave="+thetime.getTime();
}

//-->
</SCRIPT>
</head>

<body>
<a href="nextpage.htm" onclick="goto_nextpage(); return false;">Next Page</a>
</body>
</html>

SlankenOgen
06-25-2003, 05:51 AM
I'm not sure what all the button_# stuff is about but this will open nextpage.htm in a popup.

function goto_nextpage(){
thetime = new Date();
var w = window.open("nextpage.htm","myPopup","width=300, height=500");
document.location="nextpage.htm?page_load="+page_load+"&button_1="+button_1+"&button_2="+button_2+"&button_3="+button_3+"&page_leave="+thetime.getTime();
}

<a href="#" onclick="goto_nextpage(); return false;">Next Page</a>

~mgb

tomyknoker
06-25-2003, 05:58 AM
hi,
I want to do something more like this, when someone leaves the page eg they type in a new URL then nextpage.htm pops up??

Padrill
06-25-2003, 06:09 AM
Well, go to a porn site and steal the code :rolleyes:

Padrill
06-25-2003, 06:15 AM
But I should have said before posting the previous post, that it is not good practice and not respectful to the user to open up pop-ups when they want to leave the page. I hope you're not making any of those dodgy sites yourself, are you?

SlankenOgen
06-25-2003, 06:28 AM
You'll need to post all your code + html.

~mgb

tomyknoker
06-25-2003, 06:49 AM
not a porn site just a simple experiement for my course that tracks the time buttons on a pge are pushed:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!-- Begin
thetime = new Date();
page_load = thetime.getTime();
function button1(){
thetime = new Date();
button_1 = thetime.getTime();
}
function button2(){
thetime = new Date();
button_2 = thetime.getTime();
}
function button3(){
thetime = new Date();
button_3 = thetime.getTime();
}
function goto_nextpage(){
thetime = new Date();
document.location="nextpage.htm?page_load="+page_load+"&button_1="+button_1+"&button_2="+button_2+"&button_3="+button_3+"&page_leave="+thetime.getTime();
}

//-->
</SCRIPT>
</head>

<body>

<input type=button onclick="button1()" value="button1"><br>
<input type=button onclick="button2()" value="button2"><br>
<input type=button onclick="button3()" value="button3"><br>

<a href="nextpage.htm" onclick="goto_nextpage(); return false;">Next Page</a> (THIS TEXT INSTEAD OF ON CLICK RUN FUNCTION WANT ON UNLOAD RUN FUNCTION>>>SO IF USER TYPES IN ANOTHER ADDRESS POP UP OF NEXTPAGE>HTM)
</body>
</html>

SlankenOgen
06-25-2003, 07:38 AM
I think this is what you need-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">

function goto_nextpage(){
var w = window.open("myPopupPage.html","","");
}

</SCRIPT>
</head>

<body onunload="goto_nextpage();">

<input type=button onclick="button1()" value="button1"><br>
<input type=button onclick="button2()" value="button2"><br>
<input type=button onclick="button3()" value="button3"><br>

<a href="nextpage.htm" onclick="goto_nextpage(); return false;">Next Page</a> (THIS TEXT INSTEAD OF ON CLICK RUN FUNCTION WANT ON UNLOAD RUN FUNCTION>>>SO IF USER TYPES IN ANOTHER ADDRESS POP UP OF NEXTPAGE>HTM)
</body>
</html>