Javascript 警报框在 Chrome 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4996394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:08:47  来源:igfitidea点击:

Javascript Alert Boxes not working in Chrome

javascriptgoogle-chrome

提问by Frank Conry

This is weird, The following line of javascript:

这很奇怪,以下 javascript 行:

alert("test");

gives the following error in chrome:

在 chrome 中给出以下错误:

Uncaught TypeError: Property 'alert' of object [object DOMWindow] is not a function

未捕获的类型错误:对象 [对象 DOMWindow] 的属性“警报”不是函数

It also breaks when using a prompt. Oddly it works in firefox. Any ideas?

使用提示时它也会中断。奇怪的是它在 Firefox 中有效。有任何想法吗?

回答by epascarello

Do you have a another pop up blocker plug-in installed on Chrome? If you do, disable/remove it and see if the error goes away.

您是否在 Chrome 上安装了另一个弹出窗口阻止程序插件?如果这样做,请禁用/删除它并查看错误是否消失。

回答by Mihir

Is your Javascript enabled in the Chrome options? Other thing is any other js library included which might change default js behaviour?

您的 Javascript 是否在 Chrome 选项中启用?另一件事是包含任何其他 js 库,它们可能会改变默认的 js 行为?

回答by Jalali Shakib

As epascarello said its because of popup blocker plugin and I faced this problem with my localhost websites and prompt method.
So i fixed it by adding my localhost url to popup blocker's whitelist: http://localhost

正如 epascarello 所说,这是因为弹出窗口阻止程序插件,我的本地主机网站和提示方法遇到了这个问题。
所以我通过将我的本地主机 url 添加到弹出窗口阻止程序的白名单来修复它:http://localhost