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 comments, 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?
You can use the popstate method to detect those URL changes and make UI changes as needed. window. addEventListener('popstate', function (event) { // The URL changed... });
The address bar is the familiar text field at the top of a web browser's graphical user interface (GUI) that displays the name or the URL (uniform resource locator) of the current web page. Users request websites and pages by typing either the name or the URL into the address bar.
JavaScript Window Events are associated with the windows object defined for describing the events. There are other ways also which can handle the windows event like using and defining within the body tag for the events but that makes the entire code and the event a bit cumbersome to understand and evaluate.
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.com/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.com/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: http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With