Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript在iframe中读取webkitAllowFullScreen属性_Javascript_Jquery_Html_Iframe - Fatal编程技术网

如何使用javascript在iframe中读取webkitAllowFullScreen属性

如何使用javascript在iframe中读取webkitAllowFullScreen属性,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,对于以下iframe代码: <iframe src="testA.html" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> 在testA.html中,如何判断是否使用javascript包含webkitAllowFullScreen属性?这是最健壮的解决方案: if(window.frameElement && window.frameElement.hasAtt

对于以下iframe代码:

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


在testA.html中,如何判断是否使用javascript包含webkitAllowFullScreen属性?

这是最健壮的解决方案:

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

}

它利用,返回父框架元素的DOM节点,然后可以对其进行调用。

如果将allowfullscreen属性添加到iframe,则下面的变量应为
true

var fullscreenEnabled = document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled;
当iframe src位于不同的域上时,这甚至可以工作。

注意:fullscreenEnabled中的字母s是Firefox的大写字母

testA.html如何知道它被称为testA.html?我不想硬编码文件名值。啊,好吧,这有点不同。这显然只适用于同一域上的iframe(由于同源策略),因此,只要您不使用奇怪的iframe代码,上述操作就应该有效。添加了有关
布尔值
属性情况的更具体说明,这会有所帮助。如果我在父文档上有多个文件,而有些文件具有webkitAllowFullScreen属性,而其他文件没有,该怎么办?重要问题。我回到绘图板上,意识到我们不需要一个简单的解决方案。以上是完全可靠的。