Reputation: 109
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?
Upvotes: 4
Views: 30799
Reputation: 41
If you have a local variable named "window" or "open" then the function "window.open()" would not work anymore.
Upvotes: 0
Reputation: 3154
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.
Upvotes: 0
Reputation: 379
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.)
Upvotes: 1
Reputation: 1826
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.
Upvotes: 15
Reputation: 173602
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
.
Upvotes: 2
Reputation: 27364
I do not know why but below change works for me in your fiddle.
Change
var link = $(this).attr('data-link');
window.open(link);
Upvotes: 0