开发者

use html5 video player only if browser is Safari

开发者 https://www.devze.com 2023-02-05 20:15 出处:网络
I would like to use the html5 video tag only if the users browser is Safari, and if it is not, use a flash video player.

I would like to use the html5 video tag only if the users browser is Safari, and if it is not, use a flash video player.

The code below does not work (<!--[if Safari]开发者_运维技巧> conditional is not valid), but it may give you an idea of what i am looking for

<!--[if Safari]>
<video id="player" width="480" controls>
  <source src="path/to/movie.mov" />
</video>
<![endif]-->

<!--[if !Safari]>
<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">

  var flashvars = {};
  var params = {
      allowscriptaccess: "true",
      file:"path/to/movie.mov"
  };
  var attributes = {};

  swfobject.embedSWF("swf/player.swf", "player", "640", "480", "9.0.0", flashvars, params, attributes);

</script>
<![endif]-->


Never use browser detection. Use feature detection instead. You can use Modernizr for that, but in this case, you don't need any JavaScript at all to fallback to Flash if the browser doesn't support HTML5's <video> element.

See this article at Nettuts+.

0

精彩评论

暂无评论...
验证码 换一张
取 消