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

onUnload, window.open, and browser buttons

P: n/a
Hello all,

I want to open a window when a user leaves my site. I set up a function
called by onUnload. To skip the window.open if the user hasn't left my
site, I set a variable in my links and test for it in the onUnload function.
If the variable is set, don't open the window. If it's not -- if the user
is leaving my site -- do open the window.

The problem is dealing with the browser Back, Forward, and Reload buttons.
I don't want the window opening if the user hits one of them, but my flag
variable isn't set. My workaround is to set up an onLoad function that
tries to close the window if it's open. But it seems that to get that to
work, I need a defined window handle, and to define the handle I arrived at
attempting to reopen the window before closing it. But that, essentially,
causes the browser to flash, even if the (re-)open is a 1x1 window
positioned off-screen.

Is there a way to test if the window exists and is open? If there is, I
can test for that condition before trying to close it.

Or is there a better solution for my need? Would it make a difference if I
used the main browser window rather than a pop-up?

Thanks!

Seth, grimes at altaplana.com
Mar 28 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Seth Grimes said the following on 3/28/2006 6:28 AM:
Hello all,

I want to open a window when a user leaves my site.
You and every porn site on the web want that. Thankfully, I don't see
such bad habits because popup blockers make them go away before they
ever get opened.
I set up a function called by onUnload. To skip the window.open if
the user hasn't left my site, I set a variable in my links and test
for it in the onUnload function. If the variable is set, don't open
the window. If it's not -- if the user is leaving my site -- do open
the window.
And if the user has a decent pop-up blocker? They don't get the window
either way.

But, what happens if I bookmark a page, open your homepage, and then
click the bookmark to go to a sub page? I didn't leave the site but I
would, theoretically, get the pop-up. Not good.
The problem is dealing with the browser Back, Forward, and Reload
buttons.
No, the problem is you are trying to force a popup window. The user
left, leave them alone.
I don't want the window opening if the user hits one of them,
but my flag variable isn't set. My workaround is to set up an onLoad
function that tries to close the window if it's open. But it seems that
to get that to work, I need a defined window handle, and to define the
handle I arrived at attempting to reopen the window before closing it.
So now you are trying to give me a popup onload and onunload? Sheesh.
But that, essentially, causes the browser to flash, even if the
(re-)open is a 1x1 window positioned off-screen.
You can't open a 1x1 off-screen though.
Is there a way to test if the window exists and is open? If there
is, I can test for that condition before trying to close it.
You can't test for it without the reference and you can't get the
reference if you don't already have it.
Or is there a better solution for my need? Would it make a
difference if I used the main browser window rather than a pop-up?


It is a better solution not to try to force a pop-up on me.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 28 '06 #2

P: n/a
Seth Grimes wrote:
I want to open a window when a user leaves my site. <snip> Or is there a better solution for my need


Make all links in your pages which reference external pages go via a page
which contains whatever you wanted to say when they leave.

Don't attempt to display anything at all when the user leaves by entering a
URL in the address bar, selecting a saved bookmark, or indeed closing their
browser. If the user wants to leave, you should let them go quietly or else
you will just succeed in annoying them and then they won't be back.
Mar 28 '06 #3

P: n/a
Duncan Booth wrote:
Seth Grimes wrote:
I want to open a window when a user leaves my site. <snip>
Or is there a better solution for my need


Make all links in your pages which reference external pages go via a page
which contains whatever you wanted to say when they leave.


I've already done that.
Don't attempt to display anything at all when the user leaves by entering a
URL in the address bar, selecting a saved bookmark, or indeed closing their
browser. If the user wants to leave, you should let them go quietly or else
you will just succeed in annoying them and then they won't be back.


The exit page is a survey to see what users thought of the pilot site
they'll be trying. It's not going to drive them away.

Seth
Mar 28 '06 #4

P: n/a
You've told me nothing I don't already know. You also don't understand the
circumstances: we're talking about a site targeted to a small community of
users and a mechanism for soliciting their feedback. We're not talking
about a broad-market, public Web site.

If you don't have a solution, why respond?

Seth

Randy Webb wrote:
Seth Grimes said the following on 3/28/2006 6:28 AM:
Hello all,

I want to open a window when a user leaves my site.


You and every porn site on the web want that. Thankfully, I don't see
such bad habits because popup blockers make them go away before they
ever get opened.
I set up a function called by onUnload. To skip the window.open if
the user hasn't left my site, I set a variable in my links and test
for it in the onUnload function. If the variable is set, don't open
the window. If it's not -- if the user is leaving my site -- do open
the window.


And if the user has a decent pop-up blocker? They don't get the window
either way.

But, what happens if I bookmark a page, open your homepage, and then
click the bookmark to go to a sub page? I didn't leave the site but I
would, theoretically, get the pop-up. Not good.
The problem is dealing with the browser Back, Forward, and Reload
buttons.


No, the problem is you are trying to force a popup window. The user
left, leave them alone.
I don't want the window opening if the user hits one of them, but my
flag variable isn't set. My workaround is to set up an onLoad
function that tries to close the window if it's open. But it seems
that to get that to work, I need a defined window handle, and to
define the handle I arrived at attempting to reopen the window before
closing it.


So now you are trying to give me a popup onload and onunload? Sheesh.
But that, essentially, causes the browser to flash, even if the
(re-)open is a 1x1 window positioned off-screen.


You can't open a 1x1 off-screen though.
Is there a way to test if the window exists and is open? If there
is, I can test for that condition before trying to close it.


You can't test for it without the reference and you can't get the
reference if you don't already have it.
Or is there a better solution for my need? Would it make a
difference if I used the main browser window rather than a pop-up?


It is a better solution not to try to force a pop-up on me.

Mar 28 '06 #5

P: n/a
On Tue, 28 Mar 2006 08:18:15 -0500, Seth Grimes
<gr****@NOSPAMaltaplana.com> wrote:
You've told me nothing I don't already know. You also don't understand the
circumstances: we're talking about a site targeted to a small community of
users and a mechanism for soliciting their feedback. We're not talking
about a broad-market, public Web site.

If you don't have a solution, why respond?

Seth


Because Randy told you exactly why there is no solution!

Paul
Mar 28 '06 #6

P: n/a
Seth Grimes wrote:
The exit page is a survey to see what users thought of the pilot site
they'll be trying. It's not going to drive them away.

In that case simply pop up the survey when they first visit the site and
add a note at the top asking them to complete it when they have finished
their visit. Of course people with popup blockers still won't see it.

Another option (if you know who the visitors are) is to send them a follow-
up email with the survey.
Mar 28 '06 #7

P: n/a
Did Randy say there's no solution? If so, and given that he wrote "You
can't test for it without the reference and you can't get the reference if
you don't already have it," he was wrong on two counts: 1) There is a
solution, which I cited and I'll state again in a sec -- I was looking for a
*better* solution -- and 2) You CAN get the reference if you don't already
have it.

You can get the reference if you don't already have it by a (possibly
repeated) use of window.open. The problem is that call opens a new window
if one wasn't open before. I can and do immediately close the window opened
with the (possibly 2nd) call, but that causes a flickering effect. So my
solution is unacceptable appearance-wise, but it does exist all the same.

This whole situation is baroque, no dispute. I'm trying to convince the
client to skip the pop-up and go with creating a link for the user to follow
to complete the survey.

Seth

Paul Cooper wrote:
On Tue, 28 Mar 2006 08:18:15 -0500, Seth Grimes
<gr****@NOSPAMaltaplana.com> wrote:
You've told me nothing I don't already know. You also don't understand the
circumstances: we're talking about a site targeted to a small community of
users and a mechanism for soliciting their feedback. We're not talking
about a broad-market, public Web site.

If you don't have a solution, why respond?

Seth


Because Randy told you exactly why there is no solution!

Paul

Mar 28 '06 #8

P: n/a
Seth Grimes said the following on 3/28/2006 8:18 AM:
You've told me nothing I don't already know.
Then why in the world did you have to ask if you already knew everything
about it?
You also don't understand the circumstances:
Actually, I do understand it. It seems to be you that doesn't understand
the circumstance.
we're talking about a site targeted to a small community of users and a
mechanism for soliciting their feedback.
<a href="survey.html">Feedback Survey</a>

That was simple.
We're not talking about a broad-market, public Web site.
Ahh, information you left out, but it's still irrelevant as what you are
trying to accomplish is almost, if not totally, impossible to do.
If you don't have a solution, why respond?


Because I can! This is Usenet, not your help desk. You ask a question,
it gets discussed. If you get an answer to your question (which you did)
then fine, if you don't - get over it.

BTW, I *did* give a solution - don't use popups and your problem is solved.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Mar 29 '06 #9

P: n/a
Seth Grimes said the following on 3/28/2006 9:33 AM:
Did Randy say there's no solution?
Nope. I didn't. I said the solution is quite simple - don't use popups.
Then, there is no "problem" to have a "solution" to.
If so, and given that he wrote "You can't test for it without the reference
and you can't get the reference if you don't already have it,"
he was wrong on two counts:
1) There is a solution, which I cited and I'll state again in a sec --
I was looking for a *better* solution -- and
Not much of a "solution" if it doesn't work reliably. I guess it's a
difference in what you *think* is a solution and what really isn't a
solution.
2) You CAN get the reference if you don't already have it.
No you can't.
You can get the reference if you don't already have it by a (possibly
repeated) use of window.open.
That does not give you the original reference. That gives you a second
reference that happens to use the same window name to get a new
reference but it is not an original reference to the original call to
window.open.
The problem is that call opens a new window if one wasn't open before.
Precisely. And calling window.open the second time is a new reference,
not a reference to the original.
I can and do immediately close the window opened with the (possibly 2nd)
call, but that causes a flickering effect.
I bet that goes over well with your users......
So my solution is unacceptable appearance-wise, but it does exist all the same.
It is unacceptable all the way around, you just don't realize it or
don't want to admit it is all.

<a href="survey.html">Look Ma! No flickering and no popup</a>
This whole situation is baroque, no dispute. I'm trying to convince the
client to skip the pop-up and go with creating a link for the user to
follow to complete the survey.


And then you will actually have a good "solution".

Too bad you don't know how to post properly though.
Signatures can be informative.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Mar 29 '06 #10

P: n/a
Randy, you have a fourth grade style of argument:

"I'm rubber, you're glue
Whatever you say bounces of me
And sticks to you."

Seth
Randy Webb wrote:
Seth Grimes said the following on 3/28/2006 8:18 AM:
You've told me nothing I don't already know.


Then why in the world did you have to ask if you already knew everything
about it?
You also don't understand the circumstances:


Actually, I do understand it. It seems to be you that doesn't understand
the circumstance.
we're talking about a site targeted to a small community of users and
a mechanism for soliciting their feedback.


<a href="survey.html">Feedback Survey</a>

That was simple.
We're not talking about a broad-market, public Web site.


Ahh, information you left out, but it's still irrelevant as what you are
trying to accomplish is almost, if not totally, impossible to do.
If you don't have a solution, why respond?


Because I can! This is Usenet, not your help desk. You ask a question,
it gets discussed. If you get an answer to your question (which you did)
then fine, if you don't - get over it.

BTW, I *did* give a solution - don't use popups and your problem is solved.

Mar 30 '06 #11

P: n/a
JRS: In article <Sd******************************@comcast.com>, dated
Wed, 29 Mar 2006 00:21:40 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :

Too bad you don't know how to post properly though.
Signatures can be informative.


Agreed. Note the beginning of the third line of mine. Those who exhort
others to comply with properly-accepted standards should be sure to do
likewise. Don't lower yourself to Lahn level.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Mar 30 '06 #12

P: n/a
I've been using Usenet since 1985 but in recent years I've been posting only
occasionally as more and more of my forum use is on sites such as
Sourceforge.net and vendor sites (e.g., MySQL). And since I use Thunderbird
for Usenet but rarely for e-mail, I just never bothered to set up a
signature file. Given your exhortations, I've done that now. What does my
signature tell you that relates to my original question?

Seth
Dr John Stockton wrote:
JRS: In article <Sd******************************@comcast.com>, dated
Wed, 29 Mar 2006 00:21:40 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Too bad you don't know how to post properly though.
Signatures can be informative.


Agreed. Note the beginning of the third line of mine. Those who exhort
others to comply with properly-accepted standards should be sure to do
likewise. Don't lower yourself to Lahn level.

--
Seth Grimes Alta Plana Corp, analytical computing & data management
Intelligent Enterprise magazine (CMP), Contributing Editor
gr****@altaplana.com http://altaplana.com +1 301-270-0795

Mar 31 '06 #13

P: n/a
Ah, I see. While it wasn't my intention to annoy him, I'm glad I gave him
an opportunity to exercise his self-fulfilling self-righteousness.

Seth
Lee wrote:
Seth Grimes said:
I've been using Usenet since 1985 but in recent years I've been posting only
occasionally as more and more of my forum use is on sites such as
Sourceforge.net and vendor sites (e.g., MySQL). And since I use Thunderbird
for Usenet but rarely for e-mail, I just never bothered to set up a
signature file. Given your exhortations, I've done that now. What does my
signature tell you that relates to my original question?


No, you misunderstood.
When Randy said that you don't know how to post properly, and
that signatures can be informative, he wasn't telling you to
add a signature to your posts. He meant for you to read *his*
signature for clues about how you should post.

--
Seth Grimes Alta Plana Corp, analytical computing & data management
Intelligent Enterprise magazine (CMP), Contributing Editor
gr****@altaplana.com http://altaplana.com 301-270-0795
Apr 1 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.