与浏览器互动后,如何防止Iframe破坏浏览器的历史记录?

Den*_*ido 5 html javascript grafana angular

因此,在我的情况下,我使用iframe将Grafana附加到页面上(这为我提供了美观且易于使用的图形)。

可能会注意到,每次对图形进行放大或缩小(使用鼠标单击)的交互之后,Grafana的iframe都会触发我的Angular页面上的某种刷新,从而弄乱了浏览器的历史记录。我看不到Iframe的src发生任何更改以证明刷新此页面是合理的,并且它显然不会触发任何操作(例如,不会触发任何加载)。

这是正常现象吗?我该如何预防?

我正在使用Grafana版本6.2.2和Angular 6.1的脚本仪表板。

Mos*_*ini 0

Without the effective implementation of the iframe is difficult to suggest the best way to act.

The simplest solution that comes in mind is iframe's sandbox attribute:

<iframe src="my_iframe.html" sandbox></iframe>
Run Code Online (Sandbox Code Playgroud)

What's an iframe sandbox ?

The sandbox attribute enables an extra set of restrictions for the content in the iframe.

When the sandbox attribute is present, and it will:

  • treat the content as being from a unique origin
  • block form submission
  • block script execution
  • disable APIs
  • prevent links from targeting other browsing contexts
  • prevent content from using plugins (through , , , or other)
  • 阻止内容导航其顶级浏览上下文
  • 阻止自动触发的功能

sandbox 属性的值可以只是沙箱(然后应用所有限制),也可以是空格分隔的预定义值列表,这些值将删除特定限制。

参考:https: //www.w3schools.com/tags/att_iframe_sandbox.asp