简体   繁体   English

阻止浏览器在重新加载父级时保留iframe url

[英]Prevent browser from keeping iframe url when reloading the parent

I have a form inside an iframe. 我在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). 一旦用户保存了数据,我就将iframe重定向到一个只重新加载主页面的页面(因为其他一些内容取决于iframe中插入的内容)。 So the data outside the iframe ist updated and the form should appear again. 因此,iframe外部的数据将更新,表单应再次出现。

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. 问题:至少firefox(尚未在其他浏览器中测试过)保留iframe的“新”网址与重定向页面而不是源代码设置的网址。 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? 有没有办法强制进行真正的重新加载而不保留包含iframe的历史记录中的任何信息?

btw: I may use jQuery if it helps. 顺便说一句:如果它有帮助我可以使用jQuery。

Thanks. 谢谢。

You could try something along these lines ( http://jsfiddle.net/AKykZ/ ): 你可以尝试这些方面的东西( 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. 在小提琴中,单击iframe中的链接,然后单击重新加载按钮。 It sounds like you're reloading from the iframe, but this should at least get you on the right track. 听起来你正在从iframe重新加载,但这至少应该让你走上正确的轨道。

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. 但是没有在其他浏览器中测试它。

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

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