473,503 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get url from onbeforeunload object

im currently using the following to prompt the user before navigating
away from the page

// add an unload event
window.onbeforeunload = bunload;

// function to prompt user
function bunload(o){
return false;
}
however i do not want this to occur EVERY time...only when the URL is a
differnt domain.

for example if my website is www.drew.com and the user trys to navigate
away from this i want the prompt to appear, if the link is to
www.drew.com i dont want it to appear

IS THERE ANY WAY I CAN FIND OUT WHAT URL THE PAGE IS TRYING TO GO TO?

if i had that info i could use js/php to compare the values and i'd be
all set :)

i'm wondering what sort of information i can get out of the object? any
ideas???

Jul 25 '06 #1
8 7537

dr**********@gmail.com wrote:
[...]
IS THERE ANY WAY I CAN FIND OUT WHAT URL THE PAGE IS TRYING TO GO TO?
NO YOU CAN'T - AT LEAST NOT RELIABLY.
--
Rob

Jul 25 '06 #2
any chance i can take a look at the unreliable way?

also how would i find out about the properties in that object?

RobG wrote:
dr**********@gmail.com wrote:
[...]
IS THERE ANY WAY I CAN FIND OUT WHAT URL THE PAGE IS TRYING TO GO TO?

NO YOU CAN'T - AT LEAST NOT RELIABLY.
--
Rob
Jul 25 '06 #3
dr**********@gmail.com said the following on 7/24/2006 11:31 PM:
any chance i can take a look at the unreliable way?
Any chance you could learn from example and interleave your replies?
also how would i find out about the properties in that object?
In what object?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 25 '06 #4
>
Any chance you could learn from example and interleave your replies?
i dont know what your on about there, do you mean reply to parts of
quotes like this?
also how would i find out about the properties in that object?

In what object?
the code i used in my initial post shows the object (o) that gets
passed when the function is invoked, what other object is there?

Jul 25 '06 #5
dr**********@gmail.com said the following on 7/25/2006 12:06 AM:
>Any chance you could learn from example and interleave your replies?
i dont know what your on about there, do you mean reply to parts of
quotes like this?
Yes, it is referred to as interleaved replies and it is covered in the
group FAQ and Notes.
>>also how would i find out about the properties in that object?
In what object?
the code i used in my initial post shows the object (o) that gets
passed when the function is invoked, what other object is there?
Then I will reply to your original post about it rather than copy it all
here and mix up the posts.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 25 '06 #6
dr**********@gmail.com said the following on 7/24/2006 10:32 PM:
im currently using the following to prompt the user before navigating
away from the page
Not really, you just think you are. More on that below.
// add an unload event
window.onbeforeunload = bunload;

// function to prompt user
The function below does not "prompt user" at all. Try again.
function bunload(o){
return false;
}
however i do not want this to occur EVERY time...only when the URL is a
differnt domain.
And you have *NO* way of knowing that or finding it out. You can't even
know if I went to your own domain - reliably.

I am on page1.html of your site. I have a bookmark to page31.html in my
Favorites. I navigate to page31.html from my Favorites and you are going
to annoy me by asking if I want to leave your site? How user friendly
that is.
for example if my website is www.drew.com and the user trys to navigate
away from this i want the prompt to appear, if the link is to
www.drew.com i dont want it to appear
This is covered so much in the archives that it should be an FAQ Entry.
IS THERE ANY WAY I CAN FIND OUT WHAT URL THE PAGE IS TRYING TO GO TO?
No. No, you can't. No, you can't know where I am going. Did I mention
that you have no way of knowing where I am going? Besides, it's none of
your business. It is also a security violation.

var nextURL = prompt('What site are you going to next?','None of your
business');
if i had that info i could use js/php to compare the values and i'd be
all set :)
Yeah, so they say.
i'm wondering what sort of information i can get out of the object?
All you have posted is a function and a window.beforeunload event
handler. What "object" is it that you want information out of?

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

dr**********@gmail.com wrote:
any chance i can take a look at the unreliable way?
When a link on your page is clicked, set a global variable to some
value, say the domain of the link's href attribute. Use onbeforeunload
to check the domain of the current page with that of the global
variable to see if the user is heading off-site.

If the user navigates using some other method, you just assume that
they are going off-site (but they may not be). They might also click
on a link, press escape before the page goes anywhere, then go wherever
and you'll think they navigated on-site somewhere. Their browser may
not support Microsoft's proprietary onbeforeunload at all, or
JavaScript might not be available.

As I said, unreliable to the extent that it is useless for what (I
think) you want.

If you insist on bugging people who navigate away from your site,
expect them to get annoyed.

also how would i find out about the properties in that object?
What object? There is an associated event object that knows about the
event, but it knows nothing about where the page is navigating to.
Microsoft's documentation for onbeforeunload is here:

<URL:
http://msdn.microsoft.com/workshop/a...foreunload.asp
>
You can also find their documentation on the event object from the
above link. You should check out Mozilla and W3C documentation too:

<URL:http://www.w3.org/TR/DOM-Level-2-Events/>
<URL:http://developer.mozilla.org/en/docs/DOM:event>
--
Rob

Jul 25 '06 #8
thanks for all your replies, more so the the ones that were actually
helpful.

if you must no (and i dont see how it makes a difference to the
anwsering the question) the reason for this functionality is so that
the user doesnt navigate away before saving changes. The functionality
is CRITICAL to the use of the site.

I do not wish to record where the user is trying to go, just if they
are trying to leave the site, and even then i only do this so they do
not lose important data.

i think i have enough information to evaluate my options now.

i dont believe i need to explain myself anymore, thanks for everyone
posting *useful* replies, to the others....enjoy getting worked up for
no reason.

Jul 25 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10520
by: lltaylor | last post by:
Hello, Currently I use an onbeforeunload method, to do call various tidy up methods when a user exits my web application - however I now need to add additional support, for users migrating to...
6
23065
by: jennyw | last post by:
Hi, I'd like to use onbeforeunload to submit a form before leaving a page. This works in Firefox and IE. Safari, however, blithely ignores this. Does anyone know of a workaround for Safari? Or...
9
3887
by: kermit | last post by:
I keep seeing that you can use the FileSystemObject in either VB script, or Javascript on an aspx page. I added a refrence to the scrrun.dll I added importing namespaces for 'System.Object',...
4
10190
by: sowencheung | last post by:
the bug of onbeforeunload is so obvious! in IE 6 it will popup twice "sometimes" I am using the following code window.onbeforeunload = null; window.onbeforeunload = confirmExit; var...
1
4103
by: David | last post by:
I am using a process to warn users when they leave a page that there have been changes made. I took the example directly from Microsoft example I found in searching for help on the event...
1
108670
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
2
2090
Frinavale
by: Frinavale | last post by:
I'm not sure what I'm doing wrong. I am attempting to configure my object so that the object's method is called during the onbeforeunload event of the page. I have it so that it calls the...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
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
7273
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
7322
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...
1
6982
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
5572
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
4667
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...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.