Can I get an event when the address bar changes?

Is there any event that is generated when the address bar text is changed by the user? For example, when a user tries to execute javascript through the address bar.

I checked all the window events, none of them apply to the address bar.

Update

According to the comments, I tried window.onhashchange , but it only starts if the hash changes, and not for the actual URL.

The reason I need this to find a way to stop the user from executing javascript from the address bar. Thus, the timer solution will not work.

Is there any way to catch onbeforeunload and return the location back to the previous one?

+6
source share
2 answers

There is no such event (native, I mean)

Here's a question about how to make an event outside of changes in the location of the window (uses setInterval):

http://www.bennadel.com/blog/1520-Binding-Events-To-Non-DOM-Objects-With-jQuery.htm

If you use ajax, you can check this:

http://www.asual.com/jquery/address/

+2
source

There is no such trick, but maybe window.onbeforeunload can help you. With this, you can find out, at least when the user leaves your page.

See an example here: http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm

+1
source

All Articles