【问题标题】:refresh iframe when clicked browser refresh/reload button单击浏览器刷新/重新加载按钮时刷新 iframe
【发布时间】:2018-03-14 20:38:27
【问题描述】:

我有一个带有 iframe 的页面。我可以成功登录并进行一些操作。但是当我单击浏览器刷新按钮时,整个页面都会刷新,其中包含 IFrame,因此 IFrame 会随母版页刷新并返回登录屏幕。怎么只能刷新iframe页面?相关代码是

  <iframe id="iframeid" src="/Home/Index?iws=www.abc.com" sandbox="allow-same-origin allow-scripts" style="width:100%;height:100%"marginheight="0" marginwidth="0">
</iframe>


window.onbeforeunload = function (e) {
    document.getElementById('iframeid').contentWindow.location.reload();
};

【问题讨论】:

    标签: javascript iframe page-refresh onbeforeunload


    【解决方案1】:

    您在beforeunload 处理程序中唯一有用的是返回一个字符串以提示用户不要离开页面。当页面卸载时,您在处理程序中执行的任何其他操作都将被取消,这几乎立即发生。

    如果您想允许用户刷新 iframe,您可能需要在页面中创建一个按钮来执行此操作。没有任何实用的方法可以覆盖浏览器的刷新按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      • 2013-10-13
      • 2019-10-26
      • 1970-01-01
      • 2011-07-26
      • 2015-02-18
      相关资源
      最近更新 更多