pankaj_kumar6401 — 2011-12-02T06:12:05-05:00 — #1
I want to show popup when client close window and goes to another domain. I am trying to use onunload event but it also gives popup when i refresh the site and goes to any link on my site only. Is there is any way to get that whether it is a refresh event or any working way will help me.
Waiting For reply it's urgent.:(
aussiejohn — 2011-12-02T22:04:24-05:00 — #2
I've looked in to something like this before, and it isn't possible to tell whether the client is refreshing the page or closing it. The best you can probably do is set a cookie so that people will only see this popup once.
I will also add that unless there is a very good reason to use the onunload event to show a message, it should probably be avoided as it will degrade the user experience and usability of your website. When a user closes your website, they are making a conscious decision about what action they are taking, they are leaving for a reason. When then forcing someone to close an additional popup you are mentally throwing them back a step and creating frustration and maybe even anger with a user.
Simple things like this could be the difference between these users returning to your website or not.
system — 2011-12-02T22:46:56-05:00 — #3
When is your dead line?
No point in me spending time posting a possible solution if your dead line has passed or if you have got a suggestion on another website since your request is "urgent".
paul_wilkins — 2011-12-04T21:01:57-05:00 — #4
The on unload event is too late for you to be able to achieve anything. I think that it it the onbeforeunload event that you are wanting to use.
It is not possible to determine the reason wh the page is loading. It could be because the page is being closed, or refreshed, or a link is being loaded, or they are navigating to another part of your site.
A possibly useful technique could be to monitor the onclick event for when they click on a link to somewhere that is not on your site. If it's to some other site, you can raise a flag that indicates as such, so that the onbeforeunload function can then check that flag and take action if that's the case.
pankaj_kumar6401 — 2011-12-05T13:42:17-05:00 — #5
Ya we know that it will irritates the user but we really want to do a survey that why we are do it for a particular time. If I put cookies it will show popup for once but i don't need i hope you understand why..
pankaj_kumar6401 — 2011-12-05T13:44:34-05:00 — #6
If you know the possible answer I am eagerly waiting for it. Sorry for not replying earlier because i was busy for some short of business meeting.
pankaj_kumar6401 — 2011-12-05T13:47:29-05:00 — #7
Ya i have tried this event also but how would i know that it's a refresh event? I can possibly do the navigation thing.
paul_wilkins — 2011-12-05T14:43:18-05:00 — #8
That's the difficulty. It's not possible to know if it is a refresh event.
aussiejohn — 2011-12-05T16:21:32-05:00 — #9
I've been through this exact scenario for a government website a short while ago, they also wanted an exit survey.
Because of the futility of trying to get a "nice" implementation of this and many usability and accessibility concerns that I pointed out to them.
I can see if I can find an example if you're not sure of what I mean
pankaj_kumar6401 — 2011-12-06T03:28:56-05:00 — #10
Means It's not possible to do so.
Hey thanks may be i should go for any other option for doing survey.
pankaj_kumar6401 — 2011-12-06T03:32:20-05:00 — #11
I got it what are you trying to say. I also like this idea. See if you can provide me any example that would be great help to me.
aussiejohn — 2011-12-06T05:33:08-05:00 — #12
I couldn't find the website that initially inspired and figured I'd just quickly mock it up as a wireframe so you can at least get a bit of an idea
Attached to this post is an interactive PDF with wireframes that demo the (very very basic) flow of the survey. (Also available at http://afterlight.com.au/sitepoint/posts/804858-URGENT_Get-the-refresh-event-of-the-browser/SurveyButtonExample.pdf)
pankaj_kumar6401 — 2011-12-06T13:18:41-05:00 — #13