I tried running this JavaScript code in the address bar in Firefox 6:
javascript:alert("Hello")
I get a
ReferenceError: alert not defined.
It used to work fine in Firefox 5 though, and still works on Opera, Safari and Chrome. How do I fix this?
It seems using javascript:
and data:
URLs (directly in the address bar) are currently not allowed as per this comment:
FYI, I'm probably going to split this bug into multiple, short and longer term fixes.
Short term: disallow pasting of javascript: URLs into the URL bar
Longer term: additionally require that bookmarklets be "whitelisted" in the Bookmark Manager before it can run JavaScript
And this is the "bug" that was resolved in the latest version. The last comment also states:
javascript: is not actually ignored - they're run, but in an "empty" context that doesn't have any of the usual DOM methods you would expect, so most common uses (e.g. javascript:alert(1)) just throw (and thus are effectively ignored). javascript:1+1 works fine, though.
Now:
How do I fix this?
You can't, you have to wait until they decided for a proper solution. As the comment said, bookmarklets will work, but must be explicitly allowed. If you just want to test code, use either Firebug or the new Scratchpad feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With