Redirect page after exit

I need a script can redirect page after visitor want leave page(at same window)
can you please give me codes

I’m not sure I understand what you’re looking for. You want a script that when a visitor closes the window or goes to another page, they are instead redirected to another page as dictated by the script, irregardless of the user’s intentions? Or when they click on a link in your page, they go to a different page instead? Wouldn’t just a simple straight-forward link to that page be the best?

yes my friend , the first one
means when visitors closes windows or want change that page , they redirect to my site


window.onbeforeunload = function () {
    return location.href = 'page.html';
}

That will occur whenever the page changes to another one. When someone clicks on a link, when the page is refreshed, when the window is closed, when the back button is pressed, basically at any stage the existing page is removed from the window for some reason.

Important note: It is not possible to limit the conditions of when this occurs.

Edit:

The function need to return something to work, so returning the location works well.

It’s this code ?

<script language=javascript>
window.onbeforeunload = function () {location.href = 'url';}
</script>

I did it but nothing happened , i think maybe i must add something more to it
for example to body tags
right ?

I believe the function has to return something for it to work (onBeforeUnload requires it), for example:


window.onbeforeunload = function () {
    window.location = 'http://www.google.com';
    return false;
}

The dialog which appears is unavoidable.

If your testing with Opera, it won’t work. But for IE and Firefox you should get the “do you really want to leave” prompt.