Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

on leaving a page

0 views
Skip to first unread message

Benji8605

unread,
Nov 23, 2006, 8:00:56 AM11/23/06
to
Is there somekind of way i can get a function to run when a user
changes the page they are on, I figured i could use

window.addEventListener("unload", alert('leaving page!'), false);

but this doesn't work! It simply displays an alert when the page has
loaded instead of when the user has requested to go somewhere else.
Does anyone have any suggestions?

cheers

cstevens

unread,
Nov 23, 2006, 4:13:53 PM11/23/06
to

You might try adding a listener for the "beforeunload" event rather
than just "unload".

Benji8605

unread,
Nov 25, 2006, 3:41:54 PM11/25/06
to
Hi,

thanks for the suggestion, but this also seems to do exactly the same
thing, do you have any other suggestions?

Cheers,
Ben

rob rhyne

unread,
Nov 26, 2006, 4:11:44 PM11/26/06
to Benji8605, dev-ext...@lists.mozilla.org
This is a function I use to check if a user has navigated away from a
previous URL...

testChangedTabURL: function(){
//tests if the tab has been used to load a different URL
//set previousPage to whatever url you want to make sure the tab is
still loaded to, could be previously loaded page.
var previousPage = "WHATEVERURL.com";
var tabUrl = getBrowser().getBrowserAtIndex
(this.winIndex).currentURI.spec;
if(tabUrl != "undefined"){
if (tabUrl.indexOf(previousPage) >= 0) {
return false;
}else{
return true;
}
}else{
return false;
}
},

> _______________________________________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions
>

0 new messages