benhowdle89
benhowdle89

Reputation: 37464

Javascript Address Bar Hack/Trick

We've all seen this:

javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

But my question is, how does this actually work, surely if this code isnt in the source code, how does it have any effect when entered into the address bar?

Upvotes: 2

Views: 4383

Answers (3)

gabel
gabel

Reputation: 512

It is a HTML5 specification and can be applied in the page itself or via adressbar like every javascript code... like a javascript bookmarklet from twitter.

Reference:

http://www.w3.org/TR/html5/editing.html#contenteditable

Upvotes: 0

Dunhamzzz
Dunhamzzz

Reputation: 14798

Putting javascript: <anything> as a link or into the address bar will basically run the given piece of JS.

Instead of onclick or onmouseover you can just put <a href="javascript:alert('hi')">Test</a> if you really wanted.

Upvotes: 1

David Hedlund
David Hedlund

Reputation: 129792

The javascript: prefix instructs the browser to execute a script, rather than follow a link.

You probably know that you can alert a message like this:

<a href="javascript:alert('test');">Click me</a>

Now, entering javascript:alert('test'); in the address bar of the browser is the exact same thing as following that link. Hence the code will be executed. It's a feature =)

Upvotes: 0

Related Questions