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>
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.
Some browsers ignore onunload events due to widespread abuse (such as sites opening popup windows when visitors try to leave)...
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.
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...
Works for me in FF at least. Sure you haven't disabled pop-ups?
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...
In HEAD.
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...
I just removed it. Maybe I don't have the latest FF, but are you sure you haven't disabled popups?
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...
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.
But how?
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?
Might be they will, because over there I want to request them to write comments about my website
Anyway, thanx for help...
Have you heard of any command: onexit ?
Have you heard of any command: onexit ?
No. But googling javascript + exit or on exit might turn up some attempts to do what you want.
Can you give a command similar to window.open or window.popup which will not be blocked by the popup blockers?
Thanx again...
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)