onUnload, window.open, and browser buttons

S

Seth Grimes

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
 
R

Randy Webb

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

Seth Grimes

Duncan said:
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
 
S

Seth Grimes

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
 
P

Paul Cooper

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
 
S

Seth Grimes

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
 
R

Randy Webb

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

Randy Webb

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.

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?
 
S

Seth Grimes

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
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Wed, 29 Mar 2006 00:21:40 remote, seen in
Randy Webb said:
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.
 
S

Seth Grimes

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
 
L

Lee

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.


--
 
S

Seth Grimes

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
 

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,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top