Friday, March 2, 2012

How to redirect a page on before window closing time?


<script type="text/javascript" language="javascript">
window.onbeforeunload = showPic; // This is the browser window close function.
var redirecting= false;
var show_popup = true;

function showPic() {
if(show_popup)
{
    if (redirecting) return;
    setTimeout(function()
{
      setTimeout(function()
 {
            redirecting= true;
            location.href= 'http://www.google.com'; // Redirecting Url.
      }, 1000);
    }, 0);
    return '*****************************************************\n\n Wait! we have lanuch a new website \.\n If you interested to view that please click the cancel button. \n\n*****************************************************';
 }
};
//This function used to hide the popup scripts
function disablePOP()
{
  show_popup = false;
}

</script>

No comments:

Post a Comment