Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
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
add comment

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

Then javascript: URLs will work fine!

share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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