473,414 Members | 1,729 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,414 software developers and data experts.

onUnload, window.open, and browser buttons

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

Similar topics

3
by: Michael | last post by:
I am trying to allow a user to view a PDF in a new window. I currently have this working using the following: <a href="./pdf.do?parameter=01121980" target="top"><b>pdf</b></a> The problem...
3
by: Ric Castagna | last post by:
I have a form that I'm trying to handle if the viewer "leaves" without completing the entire thing. The client wants to be advised that someone one "tried" to fill out the application. Most...
2
by: Simon Wigzell | last post by:
I'm using OnUnLoad in my body statement to redirect to a function to clean things up if someone exits a form by closing it from outside the webpage code - e.g. by not using the cancel or save and...
1
by: Geoff | last post by:
I have a javascript function that runs when onunload is triggerd. So this runs when someone navigates away from the page or closes the window. I only want the code to run when the window is closed....
1
by: Nadim Attari | last post by:
Hi, how can i know whether the surfer is closing the window (web browser) or he is moving from one page to another (e.g. by clicking a link or submitting a form...) ? thanks, nadim attari
4
by: jdlwright | last post by:
Hi, well it appears (and please please correct me if I am wrong) that since some IE patch (I am using 6.0.2800.1160 SP2) the browser no longer calls the onunload handler when running outside of...
3
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a...
2
by: carlor | last post by:
Hi there, I have a form that contains a link button. When the user clicks the link button I need to enable a couple of other buttons on the page and open a new browser window giving it focus...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.