JavaScript 警报在 Firefox 6 中不起作用
栏中运行此 JavaScript 代码:
javascript:alert("Hello")
我尝试在 Firefox 6 的地址
ReferenceError:警报未定义。
它曾经在 Firefox 5 中运行良好,现在仍然可以在 Opera、Safari 和 Chrome 上运行。我该如何解决这个问题?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的可点击书签被损坏并且您想要恢复它,您可以创建一个可点击按钮,而不是使用自定义按钮 Firefox 扩展。
按钮相对于从 Scratchpad 运行的优点:
该扩展程序有点特殊,因为按钮在 Firefox chrome 级别运行,因此它们具有更多特权(您可以与浏览器的 API 进行交互),并且按钮之间没有一一对应的关系。普通的 JS 和按钮代码(需要一些调整)。更准确地说,从按钮看到的
document
和window
并不是您所期望的。但是,您可以将“好”
window
和document
分配给您的变量,然后处理这些变量(最好不要重新定义窗口;)这是我编写的示例代码这在 Fx10 中效果很好:
您必须将
theWindow.
放在它们之前,而不是直接使用全局函数(例如setTimeout
或alert
) ,并替换document
/window
与本地theDocument
/theWindow
,它似乎正在工作。然而,我还没有对非常复杂的情况进行彻底的测试。要添加按钮,右键单击已有的任何按钮,然后选择“添加新按钮...”。
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...'.
目前似乎不允许使用
javascript:
和data:
URL(直接在地址栏中)根据此评论:并且这是在 ="http://www.mozilla.com/en-US/firefox/6.0beta/releasenotes/buglist.html">最新版本。 最后一条评论还指出:
现在:
不能,你必须等到他们决定采取适当的解决方案。正如评论所说,小书签可以工作,但必须明确允许。如果您只想测试代码,请使用 Firebug 或新的 便签本功能。
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.
Felix 的答案正确地说明了为什么 URL 栏中的
javascript:
不再起作用。如果您尝试调试网页,则可以使用 Web 控制台(不要与错误控制台混淆)来替代它。在紧凑的菜单中,它位于 Web Developer 下;在完整菜单栏中,它位于“工具”下。或者您可以按 ctrl-shift-K(在 Mac 上为 cmd-shift-K)。带有大于号的横线是 JavaScript 提示符;在那里输入的代码将在当前页面的上下文中进行评估。单击该栏上方带有下划线的区域中的任何内容都可以打开检查器窗口。
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.