JavaScript 警报在 Firefox 6 中不起作用

编程入门 行业动态 更新时间:2024-10-09 22:14:57
本文介绍了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 中不起作用

本文发布于:2023-11-27 21:22:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   中不   JavaScript   Firefox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!