Accessing custom attribute from within an iframe

attributes, iframe, javascript

Solution

Try this:

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

Problem

I would like to know if it is possible to get access a custom iframe attribute within the iframe. I was thinking something along the lines of: html1.html ``` <iframe src="html2.html" customAttr="example"></iframe> ``` html2.html ``` <script>alert(window.customAttr);</script> ``` However the variable `window.customAttr` appears undefined. Does anyone know, how to get about this? Regards

Original source