【问题标题】:window.open() used in javascript not working in firefox and edgejavascript中使用的window.open()在firefox和edge中不起作用
【发布时间】:2018-07-16 12:53:52
【问题描述】:

我正在使用这样的 ajax post call,

$("#submit").on('click',function(){

    $("#submit").prop("disabled",true);
    $("#submit").prop("value","Loading...");

    $.ajax({
        type: 'POST',
        url: 'myURL',
        data: JSON.stringify({
            "mailid" : mailid,
            "a1" : a1,
            "a2" : a2,
            "a3" : a3,
            "a4" : a4,
            "a5" : a5,
            "a6" : a6,
            "a7" : a7,
            "a8" : a8,
            "a9" : a9,
            "a10" :a10,
            "dob" : age,
            "filledBy" : filledBy
        }),
        success: function () {
            //to open the score page
            window.open("score.html","_top");

            $("#submit").prop("disabled",false);
            $("#submit").prop("value","Get My Score");
        },
        error: function(error) {
            alert(error);

        }
    });
});

在成功函数中 window.open() 在 chrome 中工作正常,即页面被重定向到 score.html 但它在边缘、Firefox 和 Internet Explorer 浏览器中不起作用,而只是刷新同一页面。是否有另一种使用 window.open() 的方法,以便无论使用什么浏览器,它都会重定向到“Score.html”?

【问题讨论】:

  • 你能在 jsfiddle 提供一个例子吗?谢谢。
  • 那么问题是ajax成功还是window.open?如果您只是在点击事件中添加window.open 会怎样?它适用于所有浏览器吗?
  • 如果真的进入成功方法,听起来就像一个弹出窗口拦截器
  • 是的,我相信这是一个弹出窗口阻止程序,我尝试在我的 ajax 方法中添加“async:false”,window.open() 工作正常,但添加 async:false 不会让这两行通过 , $("#submit").prop("disabled",true); $("#submit").prop("value","加载中...");有没有办法在不使用 async:false 的情况下防止弹出窗口阻止程序?

标签: javascript jquery


【解决方案1】:

FireFox 和 Edge 允许 window.open 仅在单击时以及在其他情况下(以及 ajax 成功),询问用户是否允许打开新窗口。用户也可以选择页面不再问这个问题。

如果您想重定向到新页面,请使用此插入:

 window.location.href="score.html";

【讨论】:

  • 我尝试使用 window.location.href 仍然没有变化,页面刷新但没有打开新的 html 页面
  • 打开一个新窗口需要物理点击或用户权限。 Window.location 只是建议使用当前窗口完成操作。 @PKK
猜你喜欢
  • 2020-06-04
  • 1970-01-01
  • 2017-10-26
  • 1970-01-01
  • 2020-05-06
  • 2012-08-02
  • 1970-01-01
  • 1970-01-01
  • 2016-09-21
相关资源
最近更新 更多