How to detect navigating away from a site

H

hiriumi

Hello folks,
I have a web application that has basic authentication turned on (IIS).
What I would like to accomplish is detect whether user is navigating
away from the site or simply going to the different page using
JavaScript. I am aware that it is easy to detect where you came from
(referrer), but I haven't been able to find a way to where you're going
to. I did my fair amount of research online, but I couldn't find a
solution for this.

However, my boss told me that he has seen a website that detects the
fact that you're navigating away from your site. Does anyone know
anything about this?

Any help is much appreciated.
 
L

Lasse Reichstein Nielsen

However, my boss told me that he has seen a website that detects the
fact that you're navigating away from your site. Does anyone know
anything about this?

If you add scripts to all your links, then you can see when someone
is leaving through one of those.

If you expect a browser with an "onunload" event, then you can add
scripts to all internal links to set a flag, and in the onunload
handler act if that flag is not set. However, not all browsers
supports that proprietary event.

It will never be 100% precise. You have no way of knowing what a
user writes into the address bar.

Anyway, more importantly, why is it important ot detect what the
user is doing?

/L
 
I

Ivan Marsh

If you add scripts to all your links, then you can see when someone is
leaving through one of those.

If you expect a browser with an "onunload" event, then you can add
scripts to all internal links to set a flag, and in the onunload handler
act if that flag is not set. However, not all browsers supports that
proprietary event.

Nice!

onunload='dontunload();'
 
L

Lasse Reichstein Nielsen

Tony said:
Umm - onunload is proprietary? ....
Perhaps you are thinking of 'onbeforeunload'? which is an IE
invention, but is currently supported by Firefox (& netscape).

Yes, that's exactly the one I was thinking about :)

/L
 
L

Lasse Reichstein Nielsen

But it is still true that not all browsers support onunload properly.
For example, Opera often does not trigger onunload when a document
is unloaded.

Maybe it's because the document isn't unloaded :)

Opera keeps a number of pages running in memory after you navigate
away from them, giving instant "back" functionality. The page itself
never knew that it wasn't displayed for a while.

/L
 
H

hiriumi

Hi, Lasse. Thank you for your reply.
If you add scripts to all your links, then you can see when someone
is leaving through one of those.

Yes, that's exactly what I thought would be the only solution for this.
It will never be 100% precise. You have no way of knowing what a
user writes into the address bar.

Yes, that's very true as well.
Anyway, more importantly, why is it important ot detect what the
user is doing?
It's the security issue I'm dealing with not so much what user is
doing. We have a web application secured by IIS basic authenticaion
with SSL. But if a user navigates away from our web application to a
completely different site and click on back button even after server
side timeout, it lets you right back into our application. I know this
can very well be training issue and I also know that we should use form
authentication along with IIS security. But with the time we have it
doesn't seem to be feasible, so I was looking for a quick solution by
detecting a way to where user is going to.

Anyway, thank you very much for your help. I will continue to try to
find a good to resolve this issue.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top