javascript 类型错误:window.open 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15019992/
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
TypeError: window.open is not a function
提问by Notsogood13
I keep getting this error on firebug -> TypeError: window.open is not a function
我一直在 firebug 上收到此错误 -> TypeError: window.open is not a function
code:
代码:
$(document).ready(function()
{
$('.div').click(function()
{
var link = $(this).data('link');
window.open(link);
});
});
Isn't that function supposed to work?
那个功能不应该工作吗?
回答by Erhard Dinhobl
late but for all other coders! if you have a global variable named "open" like "open = true;" or "var open = true" or something like that, then the function "open()" would not work anymore.
迟到但对于所有其他编码员!如果您有一个名为“open”的全局变量,例如“open = true;” 或“var open = true”或类似的东西,那么函数“open()”将不再起作用。
回答by Ja?ck
Although it's not entirely clear from your question, the value of window.open
is not read-only and can therefore be changed by other code, such as:
尽管您的问题并不完全清楚,但 的值window.open
不是只读的,因此可以由其他代码更改,例如:
window.open = false;
// ...
window.open('something') // error: window.open is not a function
If you know what scripts are loaded on your page, this shouldn't be hard to do, just search for anything relating to window.open
.
如果您知道页面上加载了哪些脚本,这应该不难做到,只需搜索与window.open
.
回答by Hp Sharma
Try this
试试这个
window.open("https://www.google.com/", "_blank");
This code is working fine for me. If this doesn't work then make sure you should not declare a variable or function named with "open". (I have faced this issue once.)
这段代码对我来说很好用。如果这不起作用,请确保您不应声明以“open”命名的变量或函数。(我曾经遇到过这个问题。)
回答by Arun Joshla
If you tried it in chrome console and found it not working, try it as a script preloaded with the page. It worked in my case.
如果您在 chrome 控制台中尝试过它并发现它不起作用,请尝试将其作为页面预加载的脚本。它在我的情况下有效。
回答by Venkatesh Yeluri
If you have a local variable named "window" or "open" then the function "window.open()" would not work anymore.
如果您有一个名为“window”或“open”的局部变量,则函数“window.open()”将不再起作用。
回答by Dipesh Parmar
I do not know why but below change works for me in your fiddle.
我不知道为什么,但在您的小提琴中,以下更改对我有用。
Change
改变
var link = $(this).attr('data-link');
window.open(link);