Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
amitava82

window.open does not work in Safari

Question

Posted (edited)

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.

Edited by amitava82
Initial Revision

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 0

@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

Share this post


Link to post
  • 0

Well of course. This is just a simplified example to demonstrate the issue. Our clients use our widget on squarespace and it is breaking due to this bug.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...