Home > Technical & Creative Skills > Programming, Servers & Scripts

Meta Refresh turns off Exit Pop Script (5)


05-11-2012 02:19 AM #1 profitable ()
Meta Refresh turns off Exit Pop Script

Hey,
I have an exit pop script on a page.
I also have a meta refresh that sends the visitor to a new page after several minutes of inactivity.
Currently the meta refresh is causing the exit pop to fire
I'd like the meta refresh to not activate the exit pop

For clicks, I deactivate the pop using onClick:
<a href=”site.com” onClick=”areYouReallySure = true”>

Is it possible to do something like:
<meta HTTP-EQUIV="REFRESH" content="500; url=next.php" onSomething areYouReallySure = true">

that would deactivate the exit pop script?


05-11-2012 03:33 AM #2 zeno (Administrator)

I don't know much javascript but I think the problem here will be that the exit pop is triggered by OnUnload/OnBeforeUnload, an event that will occur whether a user presses refresh manually, F5, clicks a link or closes the tab. There is no way to differentiate between someone refreshing or closing the tab so it is probably going to be hard to supress the event for the refresh but not page exit.

An alternative would be using a javascript redirect rather than a meta refresh, at least then you could potentially supress the event in the javascript redirect code. Or using AJAX of some kind. You could also have a timed PHP redirect that sets some variable then tries to redirect, and the javascript modified to check if said variable is set, and if so to not process any further. Though that might mean on a second visit to the page the PHP session is still alive so the exit pop stays disabled.


05-18-2012 06:45 PM #3 manutv (Member)

I have the same problem!

I'm using the following javascript redirect:

Code:
<script type="text/javascript">
<!--
window.location = "http://www.domain.com"
//-->
</script>
Does anybody know what I should do to disable the exit pop when its redirecting?


05-18-2012 07:19 PM #4 dario (Member)

You need a cookie

If it's a new visit, add the meta refresh, else don't:
In the doubt (e.g. cookies disabled) doesn't refresh rather than firing the popup twice.

before the <HTML> tag add

[PHP]

<?php
$new = false;
if(isset($_COOKIE['visited']))
{
$new = false;
}
else
{
$Month = 2592000 + time();
$new = true;
setcookie('visited',date("F jS - g:i a"), $Month);
}
?>
[/PHP]

inside the <HEAD> tag add

[PHP]
<?php if($new) { echo '<meta http-equiv="refresh" content="500">'; } ?>
[/PHP]


06-06-2012 05:45 AM #5 parthenon (Member)

Dario, that code will of course function, but I don't think it's what he is trying to do.

Use an if/else conditional in the function containing your alert, the use a 2nd script with setTimeout to trip the variable used for the conditional.

Loose and untested example:

Code:
<script language="javascript" type="text/javascript"> 
var x;
function DelayRedirect()  
{
 x = 0;  
setTimeout('Redirect()', 60000);  
}  
function Redirect()  
{ 
 x = 1; 
window.location="http://www.google.com";  
} 
 function ExitPop() 
if (x == 0) {
alert("Wait don't leave");
}
else
{
}
</script> 

<body onload="DelayRedirect();" onbeforeunload="ExitPop();">
You're probably not actually using a plain ole alert, but that should give you the concept to work with.


Home > Technical & Creative Skills > Programming, Servers & Scripts