最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: window.open is not a function - Stack Overflow

programmeradmin3浏览0评论

I keep getting this error on 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?

I keep getting this error on 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?

Share Improve this question asked Feb 22, 2013 at 8:41 Notsogood13Notsogood13 1091 gold badge4 silver badges11 bronze badges 13
  • 1 Have you overridden open in the previous code? – Teemu Commented Feb 22, 2013 at 8:44
  • what is the .div link attribute..? – Dipesh Parmar Commented Feb 22, 2013 at 8:46
  • @teemu - no, i haven't – Notsogood13 Commented Feb 22, 2013 at 8:47
  • @dipesh - data-link="http://<?php echo $fav['favLink']; ?>", and when I alert(link) it shows the link properly. – Notsogood13 Commented Feb 22, 2013 at 8:48
  • and I try just window.open("www.google.com") and it still don't work – Notsogood13 Commented Feb 22, 2013 at 8:49
 |  Show 8 more comments

6 Answers 6

Reset to default 15

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.

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 = 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.

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.)

I do not know why but below change works for me in your fiddle.

Change

var link = $(this).attr('data-link');
window.open(link); 

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.

If you have a local variable named "window" or "open" then the function "window.open()" would not work anymore.

发布评论

评论列表(0)

  1. 暂无评论