ssingh
ssingh

Reputation: 334

Page redirection on page refresh not working

I want to redirect to a page on page refresh. Below is my script.

$(window).unload(function () {
    alert("exiting");
    window.location = 'http://www.google.com';
    return false;
});

Its not working. I don't know what I am missing.

Upvotes: 0

Views: 1416

Answers (2)

Pramod S. Nikam
Pramod S. Nikam

Reputation: 4541

Most of the browser cannot handle anything after unload process is done.

You should use beforeunload event instead.

$(window).bind('beforeunload', function() { 

    alert("exiting");
    window.location = 'http://www.google.com';
    return false;

});

Upvotes: 1

HDT
HDT

Reputation: 2047

try this :)

$(window).bind('beforeunload',function(){
   alert("exiting");
        window.location = 'http://www.google.com';
        return false;
});

Upvotes: 1

Related Questions