Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript alert not working in Firefox 6

Tags:

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?

like image 816
Ryan Avatar asked Jul 10 '11 20:07

Ryan


1 Answers

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.

like image 182
Felix Kling Avatar answered Sep 24 '22 02:09

Felix Kling