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?
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.
I have the same problem!
I'm using the following javascript redirect:
<script type="text/javascript"> <!-- window.location = "http://www.domain.com" //--> </script>
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]
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:
<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();">