JavaScript 警报在 Firefox 6 中不起作用 [英] JavaScript alert not working in Firefox 6

查看:26
本文介绍了JavaScript 警报在 Firefox 6 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Firefox 6 的地址栏中运行此 JavaScript 代码:

I tried running this JavaScript code in the address bar in Firefox 6:

javascript:alert("Hello")

我得到一个

参考错误:警报未定义.

ReferenceError: alert not defined.

它曾经在 Firefox 5 中运行良好,但仍然适用于 Opera、Safari 和 Chrome.我该如何解决?

It used to work fine in Firefox 5 though, and still works on Opera, Safari and Chrome. How do I fix this?

推荐答案

目前似乎不能使用 javascript:data: 网址(直接在地址栏中)允许根据此评论:

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.

短期:禁止将 javascript: URL 粘贴到 URL 栏中
长期:另外要求书签在书签管理器在它可以运行 JavaScript 之前

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

还有这是在最新版本.最后评论还指出:

javascript: 实际上并没有被忽略——它们是运行的,但是在一个空"的上下文中,没有任何你期望的常用 DOM 方法,所以最常见的用法(例如 javascript:alert(1))只是抛出(因此被有效地忽略).不过 javascript:1+1 工作正常.

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.

现在:

我该如何解决这个问题?

How do I fix this?

你不能,你必须等到他们决定一个合适的解决方案.正如评论所说,书签可以工作,但必须明确允许.如果您只想测试代码,请使用 Firebug 或新的 Scratchpad 功能.

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.

这篇关于JavaScript 警报在 Firefox 6 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆