javascript - Can I get an event when the address bar is modified? - Stack Overflow

Is there any event which is generated when the address bar text is modified by the user? Like, when use

Is there any event which is generated when the address bar text is modified by the user? Like, when user tries to execute javascript through address bar.

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

Update

As per the ments, I have tried window.onhashchange, but it only fires if the hash changes, not for the actual URL.

The reason I need this to find a way to stop the user from executing javascript from address bar. So, the timer solution won't work either.

Is there any way I can catch the onbeforeunload and set the location back to the previous one?

Is there any event which is generated when the address bar text is modified by the user? Like, when user tries to execute javascript through address bar.

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

Update

As per the ments, I have tried window.onhashchange, but it only fires if the hash changes, not for the actual URL.

The reason I need this to find a way to stop the user from executing javascript from address bar. So, the timer solution won't work either.

Is there any way I can catch the onbeforeunload and set the location back to the previous one?

Share Improve this question edited Jan 7, 2013 at 10:16 ATOzTOA asked Jan 7, 2013 at 9:39 ATOzTOAATOzTOA 36k23 gold badges99 silver badges119 bronze badges 2
  • 1 stackoverflow./questions/1930927/… – Quannt Commented Jan 7, 2013 at 9:43
  • It is not a duplicate, the other question is for hash change and it won't work for me. – ATOzTOA Commented Jan 7, 2013 at 12:14
Add a ment  | 

2 Answers 2

Reset to default 2

There is no such event (native I mean)

Here is a subject about how to make an event out of window's location changes (uses setInterval):

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

If you're using ajax, you might wanna check this out:

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

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

See an example of it here: https://web.archive/web/20211028110528/http://www.4guysfromrolla./demos/OnBeforeUnloadDemo1.htm

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745454082a4628406.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信