简体   繁体   中英

Prevent browser from keeping iframe url when reloading the parent

I have a form inside an iframe. As soon as the user saved the data I redirect the iframe to a page that does nothing more than reloading the main page (as some other content depends on what was inserted inside the iframe). So the data outside the iframe ist updated and the form should appear again.

The problem: at least firefox (haven't tested it in other browsers yet) keeps the "new" url of the iframe with the redirected page and not the one that is set by sourcecode. Something similar to autocompletion with input fields.

I do the reload by

parent.location.reload();

Is there maybe a way to force a real reload without keeping any information from the history of the containing iframes?

btw: I may use jQuery if it helps.

Thanks.

You could try something along these lines ( http://jsfiddle.net/AKykZ/ ):

document.querySelector('button').addEventListener('click', function() {
    document.querySelector('iframe').setAttribute('src', document.querySelector('iframe').getAttribute('src'));
    window.top.location.reload();
    return false;
}, false);

In the fiddle, click the link in the iframe, and hit the reload button. It sounds like you're reloading from the iframe, but this should at least get you on the right track.

Found the solution. It is pretty funny but doing the reload by

parent.location.href = parent.location.href;

makes a fresh reload of the page without keeping the history. Haven't tested it in other browsers though.

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