简体   繁体   English

iframe返回导致主窗口返回

[英]Iframe back cause main window back

here is my code: 这是我的代码:

<iframe id="ifr" src="https://www.wikipedia.org/" frameborder="0"></iframe>
<script>
  var ifr = document.querySelector("#ifr")
  ifr.src = "http://bing.com"
  ifr.contentWindow.history.back()
</script>

I expect the result is wikipedia.org, but when i open a new tab in chrome, and type /home/roroco/Dropbox/jss/ro-js/ex/test-iframe-back.html , it show "new tab", it means the main window is back 我希望结果是wikipedia.org,但是当我在Chrome中打开新标签页并键入/home/roroco/Dropbox/jss/ro-js/ex/test-iframe-back.html ,它会显示“新标签页” ,这意味着主窗口又回来了

在此处输入图片说明

how to avoid main window go back 如何避免主窗口返回

If you have the "Back Button" inside your iFrame.html page, you have to use: 如果iFrame.html页面中有“后退按钮”,则必须使用:

window.history.back();

instead of : 代替 :

ifr.contentWindow.history.back();

in your html file, add: 在您的html文件中,添加:

<input type="button" onClick="GoBack();">

and in your JavaScript file, add: 然后在您的JavaScript文件中添加:

function GoBack() {
window.history.back();
}

and you can use: 您可以使用:

parent.history.back();

inside iFrame to go back the parent of iFrame. 在iFrame中返回iFrame的父级。

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

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