Javascript 从iframe中访问自定义属性
Javascript 从iframe中访问自定义属性,javascript,iframe,attributes,Javascript,Iframe,Attributes,我想知道是否可以在iframe中访问自定义iframe属性。 我的想法大致如下: html1.html <iframe src="html2.html" customAttr="example"></iframe> <script>alert(window.customAttr);</script> html2.html <iframe src="html2.html" customAttr="example"></if
我想知道是否可以在iframe中访问自定义iframe属性。
我的想法大致如下:
html1.html
<iframe src="html2.html" customAttr="example"></iframe>
<script>alert(window.customAttr);</script>
html2.html
<iframe src="html2.html" customAttr="example"></iframe>
<script>alert(window.customAttr);</script>
警报(window.customAttr);
但是变量窗口.customAttr
似乎未定义。有人知道如何处理这件事吗?
关于试试这个:
<script>
alert(window.frameElement.getAttribute('customAttr'));
</script>
警报(window.frameElement.getAttribute('customAttr'));
是否仍要跨域访问自定义属性?