在iframe的srcdoc值中转义引号

18
根据规范,引号必须转义,即不能使用以下方式:
<iframe seamless sandbox srcdoc="<p>Yeah, you can see it <a href="/gallery?mode=cover&amp;page=1">in my gallery</a>."></iframe>


我们应该使用:

<iframe seamless sandbox srcdoc="<p>Yeah, you can see it <a href=&quot;/gallery?mode=cover&amp;amp;page=1&quot;>in my gallery</a>."></iframe>


但是在上面的例子中仅使用单引号不也可以吗:

<iframe seamless sandbox srcdoc="<p>Yeah, you can see it <a href='/gallery?mode=cover&amp;page=1'>in my gallery</a>."></iframe>
3个回答

5
您提供的规范仅指出引号被转义,因为否则srcdoc属性将会过早结束。
在您最后一个示例中,使用单引号作为值是没有问题的。
如果值内部有单引号(例如,“you're”这个词),那么您必须转义其中之一。

1

尝试将HTML转换为XHTML - 在线工具cruto

     html:
<iframe seamless sandbox srcdoc="<p>Yeah, you can see it <a href="/gallery?mode=cover&amp;page=1">in my gallery</a>."></iframe>


 xhtml:
<iframe seamless="" sandbox="" srcdoc="&lt;p&gt;Yeah, you can see it &lt;a href=" gallery?mode="cover&amp;page=1&quot;">in my gallery&lt;/a&gt;."&gt;</iframe>

它是否仍在嵌入的内容中执行脚本? - TheRealChx101

1

是的,你说得对。

我们可以使用双引号和单引号的组合来避免转义它们。

但是规范说:

转义引号 // 只是引号,没有指定是单引号还是双引号


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接