get url from onbeforeunload object

D

drewmania001

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

drewmania001

any chance i can take a look at the unreliable way?

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

Randy Webb

(e-mail address removed) 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?
 
D

drewmania001

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

Randy Webb

(e-mail address removed) said the following on 7/25/2006 12:06 AM:
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.
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.
 
R

Randy Webb

(e-mail address removed) 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?
 
R

RobG

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/author/dhtml/reference/events/onbeforeunload.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>
 
D

drewmania001

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.
 

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,780
Messages
2,569,611
Members
45,269
Latest member
vinaykumar_nevatia23

Latest Threads

Top