简体   繁体   English

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

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

I tried this, but users need to click back button twice, one to change the back the hash and another to back the iframe content: 我尝试了此操作,但用户需要两次单击“后退”按钮,一个按钮更改哈希值,另一个按钮更改iframe内容:

(TypeScript) (TypeScript)

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

And at start: 在开始时:

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

I think History Api won't help. 我认为History Api将无济于事。 I need something that works on IE9 我需要可以在IE9上使用的功能

Try this: 尝试这个:

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'));
    }
});

By using the replace() method, you can't go back to thre previous url, so your users will only need to push the back button once. 通过使用replace()方法,您无法返回到先前的URL,因此您的用户只需要按一下“后退”按钮一次。

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

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