从iframe中访问自定义属性

Accessing custom attribute from within an iframe

本文关键字:自定义属性 访问 iframe      更新时间:2023-09-26



我想知道是否可以访问iframe中的自定义iframe属性

我想的是:

html1.html

<iframe src="html2.html" customAttr="example"></iframe>

html2.html

<script>alert(window.customAttr);</script>

但是,变量window.customAttr似乎未定义

有人知道怎么做吗

问候

试试这个:

<script>
    alert(window.frameElement.getAttribute('customAttr'));
</script>