onUnload

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

onUnload

Post by moiseszaragoza »

feyd | Please use

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;
		}
	}
}
function #2 the meet of the program

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>
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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Javascript goes in

Code: Select all

..
not

Code: Select all

..
.
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Post by moiseszaragoza »

Thanks
I will read the rules

and I just saw the syntax area
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: onUnload

Post by tecktalkcm0391 »

moiseszaragoza wrote:feyd | Please use

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;
		}
	}
}
function #2 the meet of the program

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>
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][/quote]

I think you need to do  [b]<body onUnload=alertBut(false, false)>[/b] or fill in the variables for the function.
Post Reply