HTML5 data-attributes in iframe element

12,986

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.

Share:
12,986
izk
Author by

izk

12 year ActionScript veteran transitioning to Cocoa.

Updated on June 27, 2022

Comments

  • izk
    izk about 2 years

    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.