简体   繁体   中英

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:

(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. I need something that works on 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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