Doing JavaScript from the address bar cause the browser to leave the page?

I am testing a web page and I want to execute JavaScript code from the address bar to change some content (for example, change the contents of a div) I loaded the web page and typed the address bar:

javascript:document.getElementById("message").innerHTML="anotherthing"

And, after executing the above code, the browser modifies the contents of the div, but by mistake it exits the page.

How can I avoid this behavior?

Thank.

+4
source share
4 answers

Add void (0); to the end, and he will fix it.

+5
source

Another solution:

javascript: (function(){ /* Your Javascript code there */ })();
+6
source

javascript: URL , . , , JavaScript- URL-, .

JavaScript, , , javascript:, , document.getElementById(...)....

:

javascript:alert('hi');

Chrome Windows javascript: , , alert('hi'):

Example

, , , , JavaScript JavaScript . , , : JavaScript ?

0

: , JavaScript, , , div , .

Firefox: a > p > HTML " HTML".

In Chrome: Tools> Advanced Tools> Developer Tools> Elements> right-click HTML and select "Edit as HTML."

In IE: developer tools> HTML> edit icon (looks like a sheet of paper with a pencil)

0
source

All Articles