window.open(url,'_ blank');没有在iMac / Safari上工作 [英] window.open(url, '_blank'); not working on iMac/Safari

查看:156
本文介绍了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并在promise解析时设置位置。

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天全站免登陆