Click to See Complete Forum and Search --> : Exit pop


aidin819
04-28-2003, 12:47 PM
Having an issue with exit pop. I need this to only pop if user goes to another domain or closes browser window. Not when they click back or navigating through the domain.

script:

<SCRIPT LANGUAGE="Javascript">
<!--
var pc_exitpop_suppress = 1;
var PopUpFlag = true;

function popit() {
var popup_win = window.open('new_page.html','exit_popup','titlebar=no,toolbar=no,location=no,menu=no,directories=no, resizable=no,status=no,scrollbars=no,width=400,height=345,top=300');
return true;
}

function suppress() {
PopUpFlag=false;
return true;
}

function PopUpWindow () {

if(PopUpFlag) { popit(); }

}
//-->
</SCRIPT>



<body onUnload="PopUpWindow()" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

on every link:
<a OnClick="suppress();" href="/index.shtml">

pyro
04-28-2003, 12:55 PM
I believe Charles has posted the answer a while back. Here is a link: http://forums.webdeveloper.com/showthread.php?s=&threadid=4083#post19662

aidin819
04-28-2003, 01:05 PM
In that script in the url you posted, if you lick back, it will trigger the pop up. That is what i am currently getting. I would like it not to pop up if a user clicks "Back"

khurley
04-28-2003, 01:06 PM
I believe your problem is that you are using the general method "OnUnload()" indiscriminantly. The OnUnload event occurs when the user agent removes a document from a window or frame.

You may have to do something tricky like discover where the user is going (ie, a new domain ) to make the decision to popUp(), and not use the OnUnload event so generally.

aidin819
04-28-2003, 01:13 PM
I see...what about this:

Whe the pop up opens it checks the domain that opens it and if it is the same domain name, the it closes itself. If its not it remains open. Any ideas?

khurley
04-28-2003, 01:18 PM
That might work. I can't remember the javaScript method name to grab the domain though.

aidin819
04-28-2003, 01:20 PM
this is what i found...but it doesnt work:

<SCRIPT language="Javascript">
function showWin()
{
try
{
setTimeout('resizeWin()',5);
setTimeout('moveWin()',5);
self.focus();
}
catch(e)
{

window.close();
}
}
function resizeWin()
{
window.resizeTo(410,375);
}
function moveWin()
{
<!-- determine window location -->

var posLeft = (parseInt(screen.width)/2)-(410/2);
var posTop = (parseInt(screen.height)/2)-(375/2);

window.moveTo(posLeft,posTop);
}
function isBack()
{
var bBack = false
try
{
if (opener.pc_exitpop_suppress)
{
bBack = true;
}
}
catch(e)
{

// catch callee errors
if (e.number == -2147418094)
{
bBack = false;
}
else
{
bBack = true;
}
}
return bBack;
}
function openLink(URL)
{
if (opener && !opener.closed)
{
opener.location.href = URL;
}
else
{
// spawn a new window
var newWin = window.open(URL);
}
window.close();
}
function doPopup()
{
if (isBack())
{
window.close();
}
else
{
showWin();
}
}
</script>
<script language="Javascript">
{
//doPopup();
setTimeout('doPopup()', 250);
}
</SCRIPT>

khurley
04-28-2003, 01:33 PM
I am not sure about the code you posted - but I have used an applet in the past - something like this:

http://archive.corewebprogramming.com/Chapter24/wonder/GetHost.java