My JavaScript was working fine until I implemented jQuery.
I implemented jQuery to add the contents of another HTML file for my header and sidebar menu so I don’t have to change everything on every page. Since I added it, window.open
doesn’t work.
Here’s my script:
function OpenSite(site, newTab) {
if (newTab == false) {
console.log("Going to " + site);
window.open(site, '_self');
}
else {
console.log("Going to " + site + " in a new tab");
window.open(site, '_blank');
}
}
I’m getting this error in the console:
Uncaught TypeError: window.open is not a function
I’m guessing jQuery is overwriting the open
function somewhere? I’m using jQuery with a CDN so I can’t change anything in jQuery itself. The script above should have nothing to do with jQuery.
2
Answers
Whoops, I was using jQuery to load another HTML file, and in that I had a script which was overwriting the
open
function.Like you said it’s likely due to a conflict with jQuery or another library. To avoid conflicts, you can try using jQuery’s
noConflict
method.