window.open(url, '_blank');不适用于 iMac/Safari [英] window.open(url, '_blank'); not working on iMac/Safari

查看:31
本文介绍了window.open(url, '_blank');不适用于 iMac/Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个网页,让您可以从下拉列表中选择一个页面名称,然后将浏览器传输到该页面.进行传输的代码是

I've build a web page that let's you select a page name from a drop down list and then transfers the browser to that page. The code that does the transfer is

if (url){
    window.open(url, '_blank');
} 

其中url"是选择的页面.

where "url" is the page selected.

就在 window.open 行之前的控制台日志打印如下内容:

A console log just before the window.open line prints something like:

    executing: window.open(http://www.mywebsite.com/44/threats.html, '_blank')

然后浏览器会在新标签页中打开页面.

and then the browsers opens the page in a new tab.

这在 Windows 7 上适用于所有浏览器,包括 Safari.

This works fine on Windows 7 for all the browsers, including Safari.

在 iMac 上,它适用于 Firefox,但不适用于 Safari.

On an iMac it works for Firefox but not for Safari.

有谁知道为什么 iMac/Safari 不会这样做?

Does anyone know why iMac/Safari won't do this?

推荐答案

Safari 正在阻止在异步调用中对 window.open() 的任何调用.

Safari is blocking any call to window.open() which is made inside an async call.

我找到的解决此问题的方法是在进行 asnyc 调用之前调用 window.open 并在承诺解决时设置位置.

The solution that I found to this problem is to call window.open before making an asnyc call and set the location when the promise resolves.

var windowReference = window.open();

myService.getUrl().then(function(url) {
     windowReference.location = url;
});

这篇关于window.open(url, '_blank');不适用于 iMac/Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆