使用的是getScript加入回调函数内部生成一个URL我怎么能打开一个新窗口,并避免弹出窗口阻止程序?的是、回调、新窗口、弹出窗口

2023-09-10 14:14:54 作者:甘心入戏

我遇到的问题是,当我试图做类似下面的code,该窗口将被阻止弹出窗口阻止程序。我使用getScript加入脚本,这样我可以做跨域请求。我使用jQuery 1.4.2做好以下。

The issue I am having is when I try to do something like the below code, the window will be blocked by pop-up blockers. I am using getScript so that I can make cross domain requests. I am using jQuery 1.4.2 to do the below.

的code,它会被阻塞例:

//Code that gets blocked by pop-up blockers
$(document).ready(function(){
    $(".popup").click(function(){
        $.getScript("URL_To_A_Javascript_File", function(){
            window.open("dynamicURL", "_blank");
        });
    });
});

的code,获取过去的阻断剂,但犯规得到URL的时间例子:

//This code will get past the pop-up blocker, but the var url won't be updated 
//with the dynamicURL before the window.open() fires in browsers 
//like safari or chrome.
$(document).ready(function(){
    var url;
    $(".popup").click(function(){
        $.getScript("URL_To_A_Javascript_File", function(){
            url = "dynamicURL";
        });
        window.open(url, "_blank");
    });
});

我怎么能打开一个新窗口使用的是getScript加入回调函数内生成一个URL,避免弹出窗口阻止程序?

How can I open a new window using a URL that is generated inside the getScript callback function, and avoid pop-up blockers?

推荐答案

好了,它看起来像我终于想通了如何做什么,我要怎样做。

Ok, it looks like I finally figured out how to do what I was trying to do.

这个方法可以让我做弹出与出需要处理JavaScript的一个中间页。

This way allows me to do the pop-up with out the need for an intermediate page that handles the javascript.

var newWin;
$(document).ready(function(){
    $(".popup").click(function(){
        newWin = window.open();

        $.getScript("URL_To_A_Javascript_File", function() {
            newWin.location = "DynamicURL";
        });
        return false;
    });
});
 
精彩推荐
图片推荐