【问题标题】:How to change main URL in reason of navigation at iframe?由于 iframe 的导航,如何更改主 URL?
【发布时间】:2014-03-29 12:22:24
【问题描述】:

我试过这个,但用户需要点击两次返回按钮,一次更改返回哈希值,另一次返回 iframe 内容:

(打字稿)

this.iframeApp.load(() => {
    if (this.sameDomain()) {
        window.location.hash = this.iframeApp[0].contentWindow.location.toString();
    } else {
        window.location.hash = this.iframeApp.prop('src');
    }
});

一开始:

var url = window.location.hash;
if (url.length > 1) {
    url = url.substring(1);
} else {
    url = this.settings.default;
}
this.openPage(url);

我认为 History Api 无济于事。我需要在 IE9 上运行的东西

【问题讨论】:

    标签: javascript browser browser-history html5-history


    【解决方案1】:

    试试这个:

    this.iframeApp.load(() => {
        if (this.sameDomain()) {
            window.location.replace(window.location.toString() + '#' + this.iframeApp[0].contentWindow.location.toString());
        } else {
            window.location.replace(window.location.toString() + '#' + this.iframeApp.prop('src'));
        }
    });
    

    通过使用 replace() 方法,您无法返回到之前的 url,因此您的用户只需按一次返回按钮。

    【讨论】:

    • 工作,但我需要在连接新哈希之前删除哈希。 var urlWithouthash = window.location.toString().replace(/#.*$/, "");
    • 是的,忘了说 :-)
    猜你喜欢
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 2019-12-27
    • 2013-04-10
    • 2020-02-07
    • 2019-02-28
    • 2015-08-27
    • 2021-04-10
    相关资源
    最近更新 更多