Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

on leaving site pop up 2

Status
Not open for further replies.

skosterow

Technical User
Feb 23, 2002
135
US
Greetings all,

I desperatly need help! i can't seem to make the script work the way i need it to.

heres what im trying to accomplish: if the user leaves the site then it displays a pop-up stateing there leaving and that the next link is NOT affiliated with the originating site.

but if the user clicks on a link thats withing the site then the popup will not me displayed. either way is fine, IE pop java window or pop up new page.

here is the code i have created.....

<SCRIPT LANGUAGE=&quot;Javascript&quot;>
<!-- HIDE SCRIPT FROM OLD BROWSERS

// OPEN EXIT CONSOLE

var q=1;

function exit1() {

if (q==1) window.open(&quot; self.focus();}

// STOP HIDING SCRIPT FROM OLD BROWSERS -->
</SCRIPT>

please help!

thanks in advance!

- Scott Kosterow
 
You could make every link a window.open:
<a href=&quot;#&quot; onClick=&quot;window.open('win1.html');window.open('you_are_leaving_win.html');&quot;>Window1 will not open the window</a>
<a href=&quot;#&quot; onClick=&quot;window.open('win2.html');&quot;>Window2 will not open the window</a>

Rick
 
try this:
Code:
<html>
<head>
<script language='javascript'>
var tru = false;
function doClick(e)
{
eTag = e.srcElement.tagName;
if (eTag == 'A')
{
tru = true;
}
else
{tru = false;}

return false;
}
function checkClick()
{
if (tru == true) {return true;} else {window.open('exit_page.html','nombre','')}
}

</script>
</head>
<body onClick='doClick(event)' onUnload='checkClick()'> 
<a href='yadade.html'>blah</a>
<a href='yadadee.html'>blah</a>
<a href='yadad.html'>blah</a>
<a href='yadada.html'>blah</a>
</body>
</html>

hope it helps &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
Thanks you guys very much! Robert it works GREAT! and thanks Risto!

-Scott
 
Dookie2k2,

okay whats the test? what i mean is how do i say if your not within the site your leaving so heres the exit_page.html?

for example if i have a site names how can i check to see if their staying in or leaving the site?

-Scott
 
do you mean there are links on your page that lead to a different site? &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
What his script does is checks how the user leaves the page: by clicking a link, or by some other way. It doesn't do anything about links that go to other sites.

To get the effect that I think you want, you should use the method given below to navigate to different sites, and normal links to navigate within your site. For links to sites outside of your domain, do this:
<a href=&quot;the_other_site_url&quot; onClick=&quot;window.open('leaving.html');&quot;>click me!</a>

Rick
 
Yes, Dookie,

there are pages that lead to other sites ;-)

-Scott

And thanks Rick but im looking for something more centilized, but your example would work!
 
here ya go, i changed this so if they arent leaving your site it doesnt open a popup.
Code:
<html>
<head>
<script language='javascript'>
var olink = false;
function doClick(e)
{
siteName = 'rmselca.org'; //the name of your site
src = e.srcElement;
eRef = src.href;
eTag = e.srcElement.tagName;
	if (eTag == 'A' && eRef.indexOf(siteName) != -1)
	{
	olink = true;
	}
	else
	{
	olink = false;
	}
return false;
}
function checkClick()
{
if (olink == true) {return true;} else {window.open('exit_page.html','nombre','')}
}

</script>
</head>
<body onClick='doClick(event)' onUnload='checkClick()'> 
<a href='[URL unfurl="true"]http://rmselca.org'>blah</a>[/URL]
<a href='yadadee.html'>blah</a>
<a href='yadad.html'>blah</a>
<a href='yadada.html'>blah</a>
</body>
</html>
hope it helps! &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
Thanks everyone for your help. The popup is working however when we hit the refresh button the popup screen comes up eventhough the user has not left the website. How can this be fixed. Thanks again.
 
Do a search here on "popup on leaving site" if you want further information.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top