onUnload
Posted: Mon Feb 05, 2007 3:49 pm
feyd | Please use
function #2 the meet of the program
Well it works fine if i take out the <body onUnload=alertBut()>
but I need to check if they left the site via typing a new address, closing the broeser window or back fowerth btn
thanks
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ok I know i have been on this like all day and i want to thank every one that had help me
I just need a couple more things
I have a function that is working fine when i press a link I want the same function to run on unload but i am not sure that i am passing the proper parameters or doing it courtly
My first function:
This initializes the actions
[syntax="javascript"]
window.onload = initializeClicks;
// Run whenthe page is about to close
function initializeClicks()
{
if (document.links)
{
var oldClick = (document.links[0].onclick) ? document.links[0].onclick : function() {};
document.links[0].onclick = function() { doClick(); oldClick(); }
document.links[0].onmousedown=alertBut
for (var i = 1; i < document.links.length; i++)
{
var oldClickLoop = (document.links[i].onclick) ? document.links[i].onclick : function() {};
document.links[i].onmousedown=alertBut;
}
}
}
Code: Select all
function alertBut( e, evElement ) {
if( !e ) {
if( window.event ) {
//Internet Explorer
e = window.event;
} else {
//total failure, we have no way of referencing the event
return;
}
}
//Netscape compatible
if( typeof( e.which ) == 'number' ) {
e = e.which;
} else if( typeof( e.button ) == 'number' ) {
//DOM
e = e.button;
} else {
//total failure, we have no way of obtaining the button
return;
}
if( !evElement )
{ evElement = this; }
var st = evElement + ""; //converts the full address to a string
split_evElement = st.split("/"); // divides the string were ever it finds a /
var domainname=split_evElement[2] // get's the 3rd element of the array http://www.domainname.com
if (domainname=='1192.LocalServer.com' || domainname=='www.yahoo.com' || domainname=='www.moiseszaragoza.com' || domainname=='www.artofthetime.com'){
self.location.href=evElement
// goes to the page it has to go
}else{
// window.alert(domainname)
//window.alert(evElement)
window.open("survey.asp");
// opens a new window
self.location.href=evElement
// goes to the page it has to go
}
}
Code: Select all
<body onUnload=alertBut()>
<ul>
<li><a href="test3.asp">Internal </a></li>
<li><a href="http://www.yahoo.com">Yahoo</a></li>
<li><a href="http://www.moiseszaragoza.com/sites/tx/">Moises Zaragoza</a></li>
<li><a href="http://www.artofthetime.com/">AOT</a></li>
<li><a href="http://www.google.com/">pup up link google</a></li>
<li><a href="#">page link</a></li>
<br>
but I need to check if they left the site via typing a new address, closing the broeser window or back fowerth btn
thanks
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]