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.
Add void (0); to the end, and he will fix it.
Another solution:
javascript: (function(){ /* Your Javascript code there */ })();
javascript: URL , . , , JavaScript- URL-, .
javascript:
JavaScript, , , javascript:, , document.getElementById(...)....
document.getElementById(...)...
:
javascript:alert('hi');
Chrome Windows javascript: , , alert('hi'):
alert('hi')
, , , , JavaScript JavaScript . , , : JavaScript ?
: , 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)