Take the 2-minute tour ×

When I type in the address bar in Google Chrome or any other browser:


It works, but


doesn't. Why is that? How to use the address bar to change the background color?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Add ;void 0 after the bookmarklet. When the code has a non-undefine value, the page unloads, and the return value is printed.

A common way to write bookmarklets is:

javascript:(function(){ ... code ... })();
  • The anonymous function returns undefined, so the page will not unload.
  • The closure enables local variables, so that no conflicts can occur with existing global properties.

Note that in the latest versions of modern browsers (FF, Chrome), many objects are not available through the javascript:-URL in the location bar.

share|improve this answer

You need to activate this ability in your Chrome configuration. It's turned off by default.

share|improve this answer
What ability? It already executes bookmarklets. –  Jader Dias Feb 24 '12 at 16:42
alert would not show anything when the bookmarklet-in-location-bar feature is disabled. –  Rob W Feb 24 '12 at 16:45

XMLForDummies that's because of the fact that there is no access to document object from this place.

share|improve this answer

Your Answer


