最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论