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?
If your clickable bookmarklet got broken and you want it back, you can create a clickable button instead using Custom Buttons Firefox extension.
The advantages of button over running from Scratchpad:
The extension is a bit special because the buttons run at Firefox chrome level, so they're a bit more privileged (you can interact with the browser's API), and there's no 1-to-1 correspondence between normal JS and the button code (it needs some tweaking). More precisely,
document
andwindow
seen from button are not the ones you were expecting.However, you can assign the 'good'
window
anddocument
to your variables, and then work on these variables instead (better not redefine window;)Here's a sample code I written which works pretty well in Fx10:
Instead of using global functions directly (like
setTimeout
, oralert
), you have to puttheWindow.
before them, and replacedocument
/window
with localtheDocument
/theWindow
and it's seems to be working. I haven't tested it thoroughly however with very complicated cases.To add a button, right click on any button you already have and choose 'Add new button...'.
Felix's answer correctly states why
javascript:
in the URL bar doesn't work any more.The replacement for this, if you're trying to debug your web page, is the Web Console (not to be confused with the Error Console). In the compact menu, it's under Web Developer; in the full menu bar, it's under Tools. Or you can press ctrl-shift-K (cmd-shift-K on macs). The bar with a greater-than sign is a JavaScript prompt; code entered there will be evaluated in the context of the current page. Anything in the area above that bar that's underlined can be clicked on to bring up an inspector window.
It seems using
javascript:
anddata:
URLs (directly in the address bar) are currently not allowed as per this comment:And this is the "bug" that was resolved in the latest version. The last comment also states:
Now:
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.