-3

I am using window.open() functionality to open the Url in a popup window, it is working in Chrome, but it's not in Safari browser, are there any settings to open the window as a separate popup or any other solution?

3
  • 6
    See: window.open(url, '_blank'); not working on iMac/Safari, Safari is blocking any call to window.open() which is made inside an async call. Commented Jul 4, 2023 at 14:36
  • 1
    is this safari on Mac or on iOS?... and how are you attempting to open the window... Safari might be blocking this if you are auto-launching it without any user interaction. Can you show us the code you are using? Commented Jul 4, 2023 at 14:37
  • 2
    Can you show a Minimal, Reproducible Example Commented Jul 4, 2023 at 14:47

2 Answers 2

1

There's a possible cause: Safari, for some security reason, doesn't allow calling window.open() in callback function which be like:

test().then((value) => { window.open(value) })

Solution:

  1. Put your window.open() in a immediate setTimeOut.
  2. Use window.location instead

:)

Sign up to request clarification or add additional context in comments.

Comments

0

I've had a similar puzzling issue with window.open in Safari.
We generate signed S3 urls, then download files using window.open(url, '_self');

This is done inside an async function, which was working fine.
But if you have Safari's Devtools open, this does not work at all.
Closing Devtools made it work. Tested on Safari 18.3.1.

Sample code to download multiple files on click:

async function download(urls = []) {
  const entries = urls.entries()

  for (const [index, url] of entries) {
    await wait(index * 1000)
    window.open(url, '_self')
  }
}

async function wait(time = 1000) {
  await new Promise((res) => setTimeout(res, time))
}

edit: Now it's working in Safari 18.4.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.