Jump to content

window.open does not work in Safari

Recommended Posts

Given following code injected into the page:

var btn = document.querySelector("a[href=#testbtn]");

btn.addEventListener('click', function(){ window.open('https://google.com');});

It does not open new window. The click handler does get called. window.open returns null. Same piece of code tested with a simple html page works fine in same browser.

Link to comment
  • Replies 2
  • Views 6.2k
  • Created
  • Last Reply

@amitava82 Just from the brief bit of code you posted above, I'm assuming you have tag button, that when the user clicks on it you want the link (google.com) to open in a new tab?

If so, you don't need to do this in JavaScript. Simply add the url as the href value and then give it the attribute "target" with a value of "_blank". E.g:

I'm a button

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.