473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

body onunload for external links only

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
10 4294
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin Thorpe | last post by:
Does anyone know of a simple script for validating a list of external links? There are portal packages out there which do this, but I just want something simple to check links held in my database...
1
by: Perttu Pulkkinen | last post by:
To make my system's admin page safer maybe I should apply <body onunload=""> somehow so that admin session would be reseted immediately after user closes the window? But how to check easily that...
3
by: Doug Laidlaw | last post by:
I have a Web page at http://www.douglaidlaw.net/boykett/index.html which has links to three outside sources: (a) to the HTML editor, Nvu. This one works (b) to a hit counter. This shows the...
2
by: Oleg Ogurok | last post by:
Hi all, Is there a way to add a client side onunload statement into the <body> tag of a page? Thanks. -Oleg.
1
by: fernandezr | last post by:
I've successfully created a dynamic menu pulling data from a database however all links thus far have all been virtual urls such as /ABCD/default.aspx, /ABCD/profile.aspx, etc. Now I want to add...
6
by: fran7 | last post by:
Hi, Can anyone point me in the direction of some asp code to record the hits to all my internal links, not my site. I have 50 external links on one page and would like to know which of the these are...
1
by: jvallee | last post by:
I have a shoping cart page wth a registration form. The submit button takes them to GoogleCheckout. I want to call my formmail.cgi with the <body unload=...> tag. However, I get 2 error...
1
by: chiara85 | last post by:
How can I realize an external java script page, and how can I connect it to my html page?
3
by: tjtryutyu | last post by:
I know very little javascript. Nonetheless, I found some example code that opens links into a new window if they contain "external" on the "rel attribute. For example: <a href="http:example.com"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.