By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

body onunload for external links only

P: n/a
does anyone have sample code to display a pop up when a user leaves the
site? I really don't want to use this technique, but the clients
demand it.

I'm thinking something like un body onunload, catch the URL they're
linking to and parse it for our own site's url and only display the pop
up if they're different.

anyone have a sample of that code? anyone know if it's a lousy
technique? I'm open to suggestions.

thanks,

Don

Jul 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
In article <11*********************@c13g2000cwb.googlegroups. com>,
bb*****@hotmail.com wrote:
does anyone have sample code to display a pop up when a user leaves the
site? I really don't want to use this technique, but the clients
demand it.


Modern browsers do not allow a popup when you close the window.

Tell them that Windows SP2 allows the user to block pop windows.

You could implement your own close button that does a popup. Ask your
customer in a few days whether they are still using your close button or
the browser's close button.

Why does your customer want to do this? Maybe there is a more customer
friendly way of doing what they want.

I a few years back, I frequented this gaming site. They put popup
windows when I left the site. Every time you left a window, you got one
or two more. I had to reboot the pc to get out of the site. I stopped
visiting the site until I got a web browser with a popup blocker.

Robert
Jul 23 '05 #2

P: n/a
bb*****@hotmail.com wrote:
does anyone have sample code to display a pop up when a user leaves the
site? I really don't want to use this technique, but the clients
demand it.
Then educate your clients to the stupidity of what they want.
I'm thinking something like un body onunload, catch the URL they're
linking to and parse it for our own site's url and only display the pop
up if they're different.
How do you propose catching the URL if I type it in the address bar? You
can't.

Now, if I am on page1 of the site, and I have page14 in my favorites,
and I click the favorites (in IE) to go to that page, you have
absolutely *no* way to know where I went. Now, do I get the popup or
not? I left the "site" by not clicking a link in the page, yet I didn't
leave the site.
anyone have a sample of that code? anyone know if it's a lousy
technique? I'm open to suggestions.


It's not lousy, its stupid.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3

P: n/a
yeah, I uhh... appreciate that people took the time to respond.

I made a point of explaining that I didn't want to do this, but the
clients demanded it. Functional Requirements are a negotiation.
Saying that I need to "educate" the people with the purse strings is
amateurish at best. I could educate them right out of the final check
for this work. Any developer who controls their client's requirements
is either working with low level apps or leading a charmed life.

I am writing the code based on onunload, but I do appreciate the
responses.

Don

Randy Webb wrote:
bb*****@hotmail.com wrote:
does anyone have sample code to display a pop up when a user leaves the site? I really don't want to use this technique, but the clients
demand it.
Then educate your clients to the stupidity of what they want.
I'm thinking something like un body onunload, catch the URL they're
linking to and parse it for our own site's url and only display the pop up if they're different.


How do you propose catching the URL if I type it in the address bar?

You can't.

Now, if I am on page1 of the site, and I have page14 in my favorites, and I click the favorites (in IE) to go to that page, you have
absolutely *no* way to know where I went. Now, do I get the popup or
not? I left the "site" by not clicking a link in the page, yet I didn't leave the site.
anyone have a sample of that code? anyone know if it's a lousy
technique? I'm open to suggestions.


It's not lousy, its stupid.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq


Jul 23 '05 #4

P: n/a
I believe that you can get this function to work in Netscape 3.x and IE
4.x.

There have been enough complaints about popups coming up from window
close, that modern browser block pops from window close.

You do want to be hired again, but a site that people do not like does
not help you.
Robert

Jul 23 '05 #5

P: n/a
bb*****@hotmail.com wrote:
yeah, I uhh... appreciate that people took the time to respond.
Thats what we are here for <eyeroll>
I made a point of explaining that I didn't want to do this, but the
clients demanded it. Functional Requirements are a negotiation.
You are supposed to be the professional. If you are, then it is your job
to explain the flaws in the approach and offer a better alternative.
Saying that I need to "educate" the people with the purse strings is
amateurish at best.

No, thats what makes you a professional is explaining the problems and
flaws of the approach.
I could educate them right out of the final check for this work.
Sounds like you aren't qualified to do the work.

Any developer who controls their client's requirements is either working
with low level apps or leading a charmed life.

I do not control my clients requirements, but I *do* control the
solutions. And I do not work on "low level apps" nor do I lead a charmed
life.
I am writing the code based on onunload, but I do appreciate the
responses.


Then it will ultimately fail and you will get fired for not "doing your
job", and that is probably as it should be.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #6

P: n/a
What Randy says is true, you can't capture the URL in the address bar
as it is typed.

However, there is a basic "Exit Popup" script. The best solution is
not full proof. It is to write a popup script like this

var q = true;
function WaitDontLeave(){
window.open('http://whatever.com');
//other popup code
}

then your onUnload attribute in the body tag will be:
onUnload="WaitDontLeave()" the function call to your popup.

Now, the bad part is that for every href tag on the page, every form,
any tag that a visitor can click on to visit the next page in your site
must have this onClick event handler included in it.

<a href="/myfolder.nextpage.html" onClick="q=false">

Depending on the size of the site, it can be a pain. If you have a
global template, you can write a looping script to dynamically add the
onclick event handler to the tags: "a, input, ect...).

The downside is that this method, and no know method can prevent the
popups from launching if the visitor hits the BACK button, or types in
the URL from scratch, because these do not ever change the global
varialbe to false.

I have spent years in Ecommerce, and this script is used quite often
with much success. However, we usually limit it's use to just one
page, the Shopping Cart page. The thought is, if they don't move on to
the Credit Card auth page, then give them the popup with a incentive to
complete the sale. I might suggest a chat with your client about
limiting it's use to the page, or pages they most want the visitors to
take a further action on. If they don't move ahead through the normal
channels (links) then give them the popup.

Hope that was helpful.

Jeff

Jul 23 '05 #7

P: n/a
In the future Randy, please do not respond to my questions. They
clearly upset you by the tone you take with me.

Again, if you don't believe that requirements gathering is a
negotiation then this conversation is over. If you do, then you can
probably take the time to see where I'm coming from. If you can't take
that time, then that's your call.

Don

Jul 23 '05 #8

P: n/a
bb*****@hotmail.com wrote:
In the future Randy, please do not respond to my questions.
Hmmm, let me get back to you on that one.

They clearly upset you by the tone you take with me.

LOL. Usenet upset me? I want some of whatever you are smoking because
its GOOD!!!

Again, if you don't believe that requirements gathering is a
negotiation then this conversation is over.
It was over before it started. You just fail to realize the reality of
the web but that's your choice.

If you do, then you can probably take the time to see where
I'm coming from.
BTDT and learned my lesson the hard way. Looks like you will learn it
that way also. *shrug*

If you can't take that time, then that's your call.


If I didn't want to take the time, I wouldn't have bothered replying.
What you do with the information given to you is your call, not mine.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #9

P: n/a
Hey there... That was a bit harsh this is a completely valid approach to
perform certain things, but can be used in very irritating ways in the
wrong hands. I have used exit popups a number of times for surveys and
they work well. They catch people while the site is fresh in their minds
and can give you and your client valuable feedback on things like
usability. Overall my clients have had very few complaints from site
visitors. Follow the basic rules-
1. Ask permission
2. Tell people what you are doing
3. Don't write code that doesn't work
4. If at all possible don't do it to everyone. Sample ing a portion of
your traffic is something that you can usually sell to a client.

The best way that I have found to do this may not work for you but think
about it.

For surveys typically I opt the person into a survey group with a
request to participate in a study on entry. Their opt-in request opens
small new window (getting past popup blockers). Blur the new window to
get it out of the way. In the page that is loaded in the small window
evaluate the opener.location periodically using setTimeout to see if it
is not your site. If it is not, resizes the small window, redirect to
the page that you want to display and give it the focus.

This method obviously requires a second window to continue evaluating
the state of the opener and will need some more sophisticated logic on
sites using subdomains/multiple domains, but it does hold together on a
good swath of OS/Browser combinations.

good luck

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #10

P: n/a
Mike D wrote:
Hey there... That was a bit harsh this is a completely valid approach to
perform certain things, but can be used in very irritating ways in the
wrong hands.
There is *nothing* "valid" about a flawed approach. The entire idea is
flawed before you ever start.

I have used exit popups a number of times for surveys and
they work well.
Then perhaps you can answer my question I have alread asked in this
thread. Since you did not quote what you are replying to, I will ask it
again. Consider this scenario:

User bookmarks page14.html of your site.
User opens index.html of your site, navigates through page3.html.
User opens page14.html from bookmarks.

Does the user get an exit popup or not? Since they "left" the site
without clicking a link from it, yet they are still on the same site, do
they get the popup?

Second, I will *never* see a popup window when I enter or leave a site.
So, how do you give me a survey that I never see? And, how does that
"work well"?

They catch people while the site is fresh in their minds
and can give you and your client valuable feedback on things like
usability.
<a href="survey.html">Fill out a survey</a>

That does the same thing, without the unwanted side effects of popup
windows.

Overall my clients have had very few complaints from site
visitors. Follow the basic rules-
1. Ask permission
How do you "Ask permission" to give me an unwanted popup?
2. Tell people what you are doing
3. Don't write code that doesn't work
#3 alone prevents people from doing what was asked about in this thread.
There is *no* reliable way to know whether I am still on your site or
not. The most a page can tell is that you are leaving it. Given the
above scenario I asked about, it shows that any code that attempts to
determine where I went when the page unloads will *not* "work".
4. If at all possible don't do it to everyone. Sample ing a portion of
your traffic is something that you can usually sell to a client.
And a simple link to a survey does that.
The best way that I have found to do this may not work for you but think
about it.
I have. Have you?
For surveys typically I opt the person into a survey group with a
request to participate in a study on entry. Their opt-in request opens
small new window (getting past popup blockers). Blur the new window to
get it out of the way. In the page that is loaded in the small window
evaluate the opener.location periodically using setTimeout to see if it
is not your site. If it is not, resizes the small window, redirect to
the page that you want to display and give it the focus.
Open a popup, track the URL of the parent window? And without crossing
into a cross-domain security issue? Sample Code?
This method obviously requires a second window to continue evaluating
the state of the opener and will need some more sophisticated logic on
sites using subdomains/multiple domains, but it does hold together on a
good swath of OS/Browser combinations.


Example Code? I want an example of a popup code window that when I leave
your original site it can tell me the URL of the site I am on after I
leave your site.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.