0

I'm implementing a browser plugin.
I want to detect the event for document url changed to another url other than the current.
Something like this [BTW, that's pseudo code]:

$(window).bind('documenturlchange', function() {
    alert("page document url has been changed");
});

How to achieve this functionality ?

BTW, hashchange only detects "hash parts" changed in url, but it doesn't detect a whole link change (maybe to another domain for example)

Ashraf Bashir
  • 9,070
  • 12
  • 50
  • 79
  • i think this can help you http://stackoverflow.com/questions/2161906/handle-url-anchor-change-event-in-js – Mohamed Ali Mar 24 '13 at 12:14
  • http://stackoverflow.com/questions/8212845/how-to-detect-url-changes-with-jquery – btevfik Mar 24 '13 at 12:15
  • 1
    Could you elaborate on what you're trying to do? Maybe there's a better way. – Sahil Muthoo Mar 24 '13 at 12:15
  • hashchange only detect hash changes, i want to detect a full url change (maybe to another domain for example) – Ashraf Bashir Mar 24 '13 at 12:16
  • i don't its possible to detect the url change in tabs moreover its a security/privacy threat to detect/get/store the user's browsing activity, you can only access the URL of the current tab by using methods to get query string !! – Vignesh Subramanian Mar 24 '13 at 12:17

1 Answers1

0

You can make use of the window DOM objects hashchange event to detect for change in URLs. For instance, lets say the current URL is http://yourhost.com and the new url is http://yourhost.com#changed, in this case onhashchange event will be triggered.

Reference: HashChange

jjk_charles
  • 1,160
  • 10
  • 21
  • 3
    hashchange only detects "hash parts" changed in url, but it doesn't detect a whole link change (maybe to another domain for example). for example if current url is www.google.com and I moved to www.yahoo.com, this event will not be triggered – Ashraf Bashir Mar 24 '13 at 12:34