html - 更改或设置 src 或 srcDoc 属性时是否丢弃了 iframe 的 Web 浏览上下文?

标签 html w3c

根据 HTML5 官方规范,他们声明:

When an iframe element is removed from a document, the user agent must discard the nested browsing context, if any

所以我想知道如果我更改 src 或 srcDoc 属性,浏览上下文是否也会被丢弃。

规范也提到了它:

When the user agent is to process the iframe attributes, it must run the first appropriate steps from the following list

但我不清楚设置/更改此属性是否会丢弃当前浏览上下文。如果不是,JavaScript 执行上下文是否会被丢弃?

最佳答案

如果设置的 URL 与前一个 URL 的片段不同,那么简短的回答是肯定的。

又长又复杂answer is given in the current specification (顺便说一句,is now the "HTML living standard" of the WHATWG):

Whenever an iframe element with a non-null nested browsing context has its srcdoc attribute set, changed, or removed, the user agent must process the iframe attributes.

Similarly, whenever an iframe element with a non-null nested browsing context but with no srcdoc attribute specified has its src attribute set, changed, or removed, the user agent must process the iframe attributes.

steps for processing the iframe attributes状态:

If element's srcdoc attribute is specified, then: … Navigate to the srcdoc resource: navigate an iframe or frame given element … if element has a src attribute specified, or initialInsertion is false, then run the shared attribute processing steps for iframe and frame elements given element.

steps to navigate an iframe or frame这么说:

Navigate element's nested browsing context to resource…

最后,navigating a browsing context定义这个:

If historyHandling is not "reload", resource is a request, resource's url equals browsingContext's active document's URL with exclude fragments flag set, and resource's url's fragment is non-null, then:

Navigate to a fragment given browsingContext

… Otherwise, resource is a request whose url's scheme is neither "javascript" nor a fetch scheme

Run process a navigate URL scheme given resource's url and browsingContext.

此时浏览上下文更改为新资源。

请注意,规范中引用的部分仅反射(reflect)片段和将 URL 更改为“javascript”或获取方案 URL 以外的其他内容的情况。

关于html - 更改或设置 src 或 srcDoc 属性时是否丢弃了 iframe 的 Web 浏览上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60254716/

相关文章:

.net - 打开外部 DTD(w3.org、xhtml1-transitional.dtd)时发生错误。 503 服务器不可用

css - 列表项的 "marker box"是在 "principal box"内部还是旁边生成的?

css - 使主窗口水平滚动

html - 如何使用CSS设置页面图标

具有水平和垂直滚动以及固定标题和固定列宽的 html 表格

html - 伪元素 :before and overflow hidden

testing - 如何使用 W3C SVG 测试套件?

jquery - 带有推特 Bootstrap 的全身背景图像

javascript - 在 w3c 中使用 javascript 验证 onselectstart

image - 在 HTML5 中使用 <picture> <figure> 元素?