Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ General Web Design _ Redirect into new tab

Posted by: americast but from India Aug 1 2012, 04:56 AM

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>

Posted by: pandy Aug 1 2012, 07:17 AM

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.

Posted by: Christian J Aug 1 2012, 08:48 AM

Some browsers ignore onunload events due to widespread abuse (such as sites opening popup windows when visitors try to leave)...

Posted by: pandy Aug 1 2012, 09:16 AM

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.

Posted by: americast but from India Aug 1 2012, 10:23 AM

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...

Posted by: pandy Aug 1 2012, 10:42 AM

Works for me in FF at least. Sure you haven't disabled pop-ups?

Posted by: americast but from India Aug 1 2012, 11:22 AM

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...

Posted by: pandy Aug 1 2012, 02:19 PM

In HEAD.

Posted by: americast but from India Aug 2 2012, 03:03 AM

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...

Posted by: pandy Aug 2 2012, 07:46 AM

I just removed it. Maybe I don't have the latest FF, but are you sure you haven't disabled popups?

Posted by: americast but from India Aug 3 2012, 11:13 AM

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...

Posted by: pandy Aug 3 2012, 11:53 AM

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.

Posted by: americast but from India Aug 3 2012, 12:11 PM

But how?

Posted by: pandy Aug 3 2012, 12:31 PM

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

Posted by: americast but from India Aug 4 2012, 12:09 PM

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

Anyway, thanx for help...

Posted by: americast but from India Aug 5 2012, 03:39 AM

Have you heard of any command: onexit ?

Posted by: americast but from India Aug 5 2012, 03:40 AM

Have you heard of any command: onexit ?

Posted by: pandy Aug 5 2012, 05:26 AM

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...

Posted by: Darin McGrew Aug 5 2012, 05:12 PM

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.

Posted by: americast but from India Aug 8 2012, 09:28 AM

Can you give a command similar to window.open or window.popup which will not be blocked by the popup blockers?

Thanx again...

Posted by: Darin McGrew Aug 8 2012, 09:38 AM

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.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)