如何检测iframe视频是在flash还是html5视频上播放 [英] How to detect whether the iframe video is played on flash or html5 video
本文介绍了如何检测iframe视频是在flash还是html5视频上播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
在我的页面中,我嵌入了youtube。
当页面加载两个浏览器如firefox并支持flash时和没有闪光灯支持的镀铬。
现在我需要知道它是使用flash还是HTML视频加载
Hello,
In my page i am embedding youtube.
When the page is loading in two browser like firefox with flash support and chrome without flash support.
Now i need to know whether it's loaded using flash or HTML Video
<iframe id="ivideo" width="560" height="315" src="http://www.youtube.com/embed/videoname" frameborder="0" allowfullscreen></iframe>
帮我找到播放器。
Help me to find the player.
推荐答案
Html 5将使用媒体元素。 Flash将使用一个对象元素。
选择一个起始元素并进行递归循环直到找到答案。
这是递归函数,用于检查每个元素的标记名称。
Html 5 will use a media element. Flash will use an object element.
pick a starting element and do a recursive loop until you find the answer.
This is the recursive function that will check the tag name of each element.
function checkForPlayer(el)
{
var result = null;
if(el.tagName)
if(el.tagName.toLowerCase() == 'object')
result = 'flash';
else if(el.tagName.toLowerCase() == 'media')
result = 'html5';
if(result != null)
return result;
for(var i = 0; i < el.childNodes.length; i++)
{
result = checkForPlayer(el.childNodes[i]);
if(result != null)
return result;
}
}
这是如何使用它。
This is how to use it.
var myElement = document.getElementById('myElementId');
var result = checkForPlayer(myElement);
var resultText = result == null ? 'none' : result;
alert(resultText);
这篇关于如何检测iframe视频是在flash还是html5视频上播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文