从html5< video>添加或删除控件属性标签 [英] add or remove controls attribute from html5 <video> tag

查看:860
本文介绍了从html5< video>添加或删除控件属性标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,根据用户代理字符串将controls属性添加到视频标记中。

I am looking for a method to add the controls attribute to a video tag based upon the user agent string.

我不希望在除Ipad和Android之外的任何浏览器或设备上都存在controls属性。所以我认为用户代理是最好的识别方式,因为ipad和android这两个词存在于各自的UA标题中。

I do not wish to have the controls attribute present on any browser or device other than Ipad and Android. So i thought that user agent was the best way to identify because the words ipad and android are present in their respective UA header.

实现目标的最佳方法是什么?
我试过这个没有运气:

What is the best way to accomplish my goal? I've tried this with no luck:

<script type="text/javascript">
  var myVideo = document.getElementById("myVideo");
  var agent = navigator.userAgent.toLowerCase();
  var addAttr = (agent.indexOf('ipad')!=-1) || agent.indexOf('android')!=-1);
  if (addAttr) {
    myVideo.setAttribute("controls","controls");
  }
  else {
    document.write("");
  }
</script>

这是我的html5视频内容

and here is my html5 video stuff

<video id="myVideo" width="1170" height="324" preload="metadata" autoplay="true">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0"
    width="1170" height="324" >
    <param name="movie" value="movie.swf">
    <param name="quality" value="high">
    <param name="play" value="true">
    <param name="LOOP" value="false">
    <embed src="movie.swf" width="1170" height="324" play="true" loop="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" 
    type="application/x-shockwave-flash">
    </embed>
  </object>
</video>

任何帮助都将不胜感激!

Any help would be appreciated!

推荐答案

你可以用jQuery做到这一点:

You can do it with jQuery:

//Add
$('#myVideo').prop("controls", true);



//Remove
$('#myVideo').prop("controls", false);

这篇关于从html5&lt; video&gt;添加或删除控件属性标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆