Can custom data-attributes set on an iframe be accessed by the iframe's content?
Example:
<iframe src="foo.html" data-something="123"></iframe>
Is there a way to access data-something's value form the iframe's document?
Thanks.
Note − The frameborder, marginwidth, longdesc, scrolling, marginheight attributes deprecated in HTML5.
Attributes used with iframe are srcdoc, name, src.
The <iframe> element is still valid in HTML5. Depending on what exact interaction you need there might be different APIs. For example there's the postMessage method which allows you to achieve cross domain javascript interaction.
Yes, use the frameElement
attribute.
window.frameElement.getAttribute('data-something');
Demo: http://jsfiddle.net/Ehj2Q/
Of course this does not work at all if the iframe's content are from a different origin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With