body onunload for external links only

B

bbcrock

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
 
R

Robert

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
 
R

Randy Webb

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

bbcrock

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
 
R

Robert

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
 
R

Randy Webb

yeah, I uhh... appreciate that people took the time to respond.

Thats what we are here for said:
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?
 
S

Spats30

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
 
B

bbcrock

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
 
R

Randy Webb

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

Randy Webb

Mike said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,097
Latest member
RayE496148
Top