同步iframe在Chrome和Edge中

发布于 2025-01-23 15:30:17 字数 1942 浏览 2 评论 0原文

以下脚本用于加载iframe web应用程序。

          function openCashier(destination) {
                postIsAnonymous(function (data) {
                    if (data.IsAnonymous) {
                        window.parent.location.replace('<%= ResolveUrl("~/Popup/login") %>');
                    } else {
                        stateReset('showUserBtn');
                        WCore.OpenTab('cashier');
                        $("#cashierPopup").addClass(destination);
                        $("#cashierFrame").attr('src', '<%= ResolveUrl(Routing.GetUrl("Root-TPAutologin")) %>?Destinazione=' + destination);
                    }
                });
             }

在Firefox中,一切正常,而在Edge和Chrome中,我会收到错误404。如果我尝试将iframe的内容加载到单独的浏览器会话中,则一切都起作用。 我试图如下编辑JavaScript,担心一个异步问题:

            function openCashier(destination) {
                setTimeout(function () {
                    postIsAnonymous(function (data) {
                        if (data.IsAnonymous) {
                            window.parent.location.replace('<%= ResolveUrl("~/Popup/login") %>');
                    } else {
                        stateReset('showUserBtn');
                        WCore.OpenTab('cashier');
                        $("#cashierPopup").addClass(destination);
                            $("#cashierFrame").attr('src', '<%= ResolveUrl(Routing.GetUrl("Root-TPAutologin")) %>?Destinazione=' + destination);
                        }
                    });
                }, 1000 * 20);
             }

通过此技巧,该问题通过非常糟糕的表演解决了

后匿名代码如下:

function postIsAnonymous(successFunc) {
  $.ajax({
    type: "POST",
    url: '?checkIsAnonymous=1',
    cache: false,
    contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
    processData: false,
    success: successFunc
  });
}

您是否有任何建议可以给我解决问题 优雅的方式?谢谢

the following script is used to load in a IFRAME a web application.

          function openCashier(destination) {
                postIsAnonymous(function (data) {
                    if (data.IsAnonymous) {
                        window.parent.location.replace('<%= ResolveUrl("~/Popup/login") %>');
                    } else {
                        stateReset('showUserBtn');
                        WCore.OpenTab('cashier');
                        $("#cashierPopup").addClass(destination);
                        $("#cashierFrame").attr('src', '<%= ResolveUrl(Routing.GetUrl("Root-TPAutologin")) %>?Destinazione=' + destination);
                    }
                });
             }

In Firefox everything works fine, while in Edge and Chrome I get error 404. If I try to load the contents of the IFRAME in a separate browser session everything works.
I tried to edit the javascript as follows, fearing an asynchronism problem:

            function openCashier(destination) {
                setTimeout(function () {
                    postIsAnonymous(function (data) {
                        if (data.IsAnonymous) {
                            window.parent.location.replace('<%= ResolveUrl("~/Popup/login") %>');
                    } else {
                        stateReset('showUserBtn');
                        WCore.OpenTab('cashier');
                        $("#cashierPopup").addClass(destination);
                            $("#cashierFrame").attr('src', '<%= ResolveUrl(Routing.GetUrl("Root-TPAutologin")) %>?Destinazione=' + destination);
                        }
                    });
                }, 1000 * 20);
             }

With this trick the problem is solved with very bad performances.

PostIsAnonymous code is the following :

function postIsAnonymous(successFunc) {
  $.ajax({
    type: "POST",
    url: '?checkIsAnonymous=1',
    cache: false,
    contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
    processData: false,
    success: successFunc
  });
}

Do you have any suggestions to give me to solve the problem in a more
elegant way? Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

番薯 2025-01-30 15:30:17

我通过以下代码解决了问题。

 function openCashier(destination) {
                var dest = destination;
                sessionManager.isAnonymous()
                    .then((data) => {
                        if (data.IsAnonymous) {
                            window.parent.location.replace('<%= ResolveUrl("~/Popup/login") %>');
                        }
                        else {
                            stateReset('showUserBtn');
                            WCore.OpenTab('cashier');
                            $("#cashierPopup").addClass(dest);
                            $("#cashierFrame").attr('src', '<%= ResolveUrl(Routing.GetUrl("Root-TPAutologin")) %>?Destinazione=' + dest);
                        }
                    })
                    .catch((err) => {
                        console.error(err);
                    });
            }

 var sessionManager = {
    isAnonymous: () => {
    return new Promise((resolve, reject) => {
        $.ajax({
            type: "POST",
            url: '?checkIsAnonymous=1',
            cache: false,
            contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
            processData: false,
            success: function (data) {
                resolve(data);
            },
            error: function (data) {
                reject(data);
            }
        });
    })
   }
 }

I solved the problem with the following code.

 function openCashier(destination) {
                var dest = destination;
                sessionManager.isAnonymous()
                    .then((data) => {
                        if (data.IsAnonymous) {
                            window.parent.location.replace('<%= ResolveUrl("~/Popup/login") %>');
                        }
                        else {
                            stateReset('showUserBtn');
                            WCore.OpenTab('cashier');
                            $("#cashierPopup").addClass(dest);
                            $("#cashierFrame").attr('src', '<%= ResolveUrl(Routing.GetUrl("Root-TPAutologin")) %>?Destinazione=' + dest);
                        }
                    })
                    .catch((err) => {
                        console.error(err);
                    });
            }

 var sessionManager = {
    isAnonymous: () => {
    return new Promise((resolve, reject) => {
        $.ajax({
            type: "POST",
            url: '?checkIsAnonymous=1',
            cache: false,
            contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
            processData: false,
            success: function (data) {
                resolve(data);
            },
            error: function (data) {
                reject(data);
            }
        });
    })
   }
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文