Help - Search - Members - Calendar
Full Version: Redirect into new tab
HTMLHelp Forums > Web Authoring > General Web Design
americast but from India
I want my users to go to another website when they close my website. So, I used the given code but I cannot understand what is wrong in it. Please help. Thanx for any help...

[code]
<script type="text/javascript">

window.onunload = unloadPage;

function unloadPage()
{
window.open("exampleurl","_blank")
}
</script>
pandy
What happens now? Nothing or does it open a new window? What browser(s)?

I don't think you should have "_blank" there. If you want to name the window, choose your own name, not one of the predefined ones. And if you have more parameters then the URL, you need to use the whole shebang. Also, it's probably better to use onbeforeunload than onunload.
Christian J
Some browsers ignore onunload events due to widespread abuse (such as sites opening popup windows when visitors try to leave)...
pandy
Yeah, I can't get it to work in Iron. But I never use that browser for personal use and there may be some popup blocker setting that I don't find.
americast but from India
When the window is closed, nothing happens. I tried it with Chrome, Firefox and Opera. I used the full url. Do you have any other ideas of how to accomplish my target?

Thanx...
pandy
Works for me in FF at least. Sure you haven't disabled pop-ups?
americast but from India
where have you put the script? Under the <body> tag or the <head> tag? I had used it in the <head> tag...

Thanx for any help...
pandy
In HEAD.
americast but from India
What did you write in place of "_blank"? Did you use single quotes in place of double? If possible please mention the exact lines you used.

Thanx again...
pandy
I just removed it. Maybe I don't have the latest FF, but are you sure you haven't disabled popups?
americast but from India
Great! On disabling popups, it works fine. But, my users will always have popups enable. How to bypass this popup?

Also, I have found that the new page (linked in the javascript) opens even if a I click a link in my website. But I do not want that. The reason is that I want to link my website to a 'Thank You' page, which the user should get only after he goes away from my site. The links given inside my site are the ones which are linked to different pages of my site. See if you can find a solution to this.

Thanx...
pandy
So it works now?

That's a whole lot more complicated. I guess you would have to make JavaScript first check if the clicked link leads to a page on your domain and if so stop there.
americast but from India
But how?
pandy
I'm not sure. I think it would involve event listeners (google that) for checking the link clicks, but there also needs to be some logic to check if a link was clicked at all when the page unloads so the pop-after will fire if the window is simply closed.

BTW you realize no one will like this way of saying Thank you, don't you? wink.gif
americast but from India
Might be they will, because over there I want to request them to write comments about my website smile.gif

Anyway, thanx for help...
americast but from India
Have you heard of any command: onexit ?
americast but from India
Have you heard of any command: onexit ?
pandy
No. But googling javascript + exit or on exit might turn up some attempts to do what you want.

QUOTE
Might be they will, because over there I want to request them to write comments about my website smile.gif


Im sure that will make them thrilled...
Darin McGrew
QUOTE
Have you heard of any command: onexit ?
Perhaps you're referring to the onclose event handler.

It's still a bad idea to use it to pester visitors to your site.
americast but from India
Can you give a command similar to window.open or window.popup which will not be blocked by the popup blockers?

Thanx again...
Darin McGrew
QUOTE
Can you give a command similar to window.open or window.popup which will not be blocked by the popup blockers?
If you could, then I'm sure it wouldn't be long before popup blockers started blocking the new command too.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.