0

With Firefox I can type in the location bar "javascript:" followed by some JavaScript code and have this code executed and the result displayed in the page. For example javascript:x = 3 displays 3 in the page.

However with Chrome nothing is displayed. Is there a way to do this in Chrome?

1

You could do something like:

javascript:x=3;alert(x)

Or:

javascript:x=3;document.write(x)

At least on Chrome for OS X, neither of these work on the new tab page; you must first open any other page first. Loading about:blank does just fine.

  • Nope, doesn't work for me. Or it doesn't work if I paste the string. Typing it in seems to work. Google's autocomplete seems to be interfering and won't turn off. Makes it feel like IE. – Malvolio Oct 19 '11 at 22:37
  • chrome doesn't like spaces: so javascript: x=3; alert(x); is different from javascript:x=3; alert(x). The former doesn't work, the latter does. – user257309 Sep 25 '13 at 13:34
0

Start Chrome with the --enable-user-scripts command line option.

Then javascript: URLs will work fine!

  • 2
    This is not actually necessary, at least on OS X. Entering javascript:window.alert("hello"); works just fine without it. – Daniel Beck Jun 30 '12 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.