Why does the page go blank when injecting JavaScript code via the address bar?

118 views Asked by At

So if I want to make a change, for example in this page (stackoverflow.com), using:

javascript:document.getElementById("hlogo").innerHTML = "10";

The page goes blank, only showing the string "10", even though the source code is still there.

Yet if I do this in an HTML document internally via the JavaScript console it doesn't remove the rest of the content visually.

1

There are 1 answers

0
A. Andres On BEST ANSWER

Append a void(0) or any expression returning an undefined value:

javascript:document.getElementById("hlogo").innerHTML = "10";void(0);

This answer explains this behavior well: https://stackoverflow.com/a/1291950/689788