admin管理员组

文章数量:1303404

For the following iframe code:

<iframe src="testA.html" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

Inside testA.html, how do I tell if the webkitAllowFullScreen attribute is included using javascript?

For the following iframe code:

<iframe src="testA.html" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

Inside testA.html, how do I tell if the webkitAllowFullScreen attribute is included using javascript?

Share Improve this question edited Dec 13, 2011 at 1:10 Yahel 37.3k23 gold badges106 silver badges154 bronze badges asked Dec 12, 2011 at 23:26 wwwuserwwwuser 6,37210 gold badges57 silver badges65 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

If the allowfullscreen attributes are added to the iframe the variable below should be true

var fullscreenEnabled = document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled;

This even works when the iframe src is on a different domain.
Note: the letter s in fullscreenEnabled is uppercase for Firefox

This is the most robust solution:

if(window.frameElement && window.frameElement.hasAttribute("webkitAllowFullScreen")){

}

It utilizes window.frameElement, which returns the DOM node of the parent framing element, which you can then make a hasAttribute call against.

本文标签: jqueryHow to read webkitAllowFullScreen attribute in iframe using javascriptStack Overflow