繁体   English   中英

如何在iframe上导航更改主网址?

[英]How to change main URL in reason of navigation at iframe?

我尝试了此操作,但用户需要两次单击“后退”按钮,一个按钮更改哈希值,另一个按钮更改iframe内容:

(TypeScript)

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上使用的功能

尝试这个:

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,因此您的用户只需要按一下“后退”按钮一次。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM