PDA

View Full Version : JS addeventlistener on url for change?



bardic
December 7th, 2009, 10:33 AM
Hey all,
I'm like to add an eventlistener to a script i'm working on that fires whenever the url is change but so far I'm not having any luck. I'm not even sure if this is possible >.<

Here's what I've been trying :



var url = document.location;
url.addEventListener('urlChange',onChange,false)


Should I just use a setInterval?

Thanks

jwilliam
December 7th, 2009, 02:10 PM
I'm pretty sure that won't work. What are you trying to achieve?

bardic
December 7th, 2009, 08:21 PM
I am just trying to figure out what is the best way to detect url changes without using an existing library, but as you are guess I'm not very good at js >.<

actionAction
December 7th, 2009, 10:28 PM
You can detect the page is being left using onunload:


window.onunload = function(){
//do your stuff here
}

Swooter
December 10th, 2009, 06:40 AM
You can also use the onbeforeunload handler