【问题标题】:Posting a page to an iframe causing pop-up blocker to prevent the post action将页面发布到 iframe 会导致弹出窗口阻止程序阻止发布操作
【发布时间】:2012-08-14 18:56:22
【问题描述】:

我正在尝试从帖子中加载一个页面以将其加载到 iframe 中,其中 POST 变量与将要加载的页面一起发送。没有明确打开新窗口的内容,但我在 FF 和 Chrome 中收到弹出窗口阻止通知。 IE 还没有阻止 POST,但可能会在未来的更新中。下面列出的是触发弹出的代码。

gamePage.name = 'game_page';
setTimeout('', 100);
gamePage.onload = setTimeout("$.download(getCompletePath() +'account/SomeFile.php',  gameId='+game_Id+'&playMode=J', 'post', 'game_page')", 0);

这里是 $.download 函数:

jQuery.download = function(url, data, method, target){
    //url and data options required
    if( url && data ){ 
        //data can be string of parameters or array/object
        data = typeof data == 'string' ? data : jQuery.param(data);
        //split params into form inputs
        var inputs = '';
        jQuery.each(data.split('&'), function(){ 
            var pair = this.split('=');
            inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
        });
        //send request
        jQuery('<form action="'+ url +'" method="'+ (method||'post') +'" target="' + target +'">'+inputs+'</form>')
        .appendTo('body').submit().remove();
    };
};

目前,我们正在通过 GET 执行此操作,但如果不是所有 GET 请求,我们将尽可能切换到 POST。在发布到 iframe 时如何绕过弹出窗口阻止程序的任何帮助将不胜感激。

【问题讨论】:

  • 我也在做同样的事情,但 Chrome 工作正常; IE 和 Firefox 出现弹出窗口阻止程序错误。

标签: jquery post iframe popup


【解决方案1】:

只使用一个简单的 DIV,而不是 iFrame。

调用 jQuery.post() 方法,并使用 jQuery.html(/response/) 函数将响应作为 div 的 innerHTML。

类似的东西:

$.post("urlToLoad.ext", { name: "John", time: "2pm" })
.success(function(data) {
    $('#yourDivID').html(data);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多