没有源代码的HTML5视频标签? [英] HTML5 Video tag with no source?
问题描述
如果我有HTML5 VIDEO标记,但是在元素中既不包含SRC属性也不包含SOURCE标记,是否有任何已定义的行为?这仍然是有效的HTML,如果是这样,那么(HTML5能力的)浏览器应该做什么 - 忽略该元素或显示它的内容?
是的,有定义的行为; HTML5试图为任何情况提供定义的行为,以便在浏览器之间产生差异,以减少不兼容性,即使在处理无效文档时也是如此。
规范,它看起来像它没有 src
属性或源
元素是无效的:
< blockquote>
内容模型:
如果
元素具有src属性:
透明,但没有媒体元素
后代。 >
如果元素没有
具有src属性:一个或多个
源元素,那么透明,
但没有媒体元素
后代。 p>
这似乎表明它必须有一个 src
属性或一个源
子元素。但是 Validator.nu 和 W3C Validator 似乎认为这是一个有效的文档:
<!DOCTYPE html>
< title>视频测试< /标题>
< video>< / video>
无论是否有效,行为都在资源选择算法,如下所示:
⌛否则,媒体元素的
既不是src属性也不是源
元素child:将networkState设置为
NETWORK_EMPTY,并放弃这些步骤;
同步部分结束。
这意味着准备状态为 HAVE_NOTHING
HAVE_NOTHING
(数值0)
没有相关信息媒体
资源可用。
当前播放位置的数据不可用
。
networkState属性为
NETWORK_EMPTY
的媒体元素始终位于
HAVE_NOTHING
状态。
在该状态下,视频由 如果没有视频数据可用( 当它没有被表示时,这意味着它只是一个通用的框;比如 请注意,它不会在支持 内容可能在 Is there any defined behaviour if I have an HTML5 VIDEO tag but include neither a SRC attribute nor SOURCE tags inside the element? Would this still be valid HTML, and if so, what should the (HTML5 capable) browser do - ignore the element or display it's contents? Yes, there is defined behavior; HTML5 is trying to provide defined behavior for any case in which it could make a difference between browsers, to reduce incompatibility, even when dealing with invalid documents. From my reading of the spec, it looks like it is invalid to have no Content model: This seems to indicate to me that it must have either a Regardless of whether it's valid, the behavior is defined in the resource selection algorithm as follows: ⌛ Otherwise the media element has
neither a src attribute nor a source
element child: set the networkState to
NETWORK_EMPTY, and abort these steps;
the synchronous section ends. This implies a ready state of In that state, the video is represented by its poster frame, or nothing: When no video data is available (the
element's readyState attribute is
either When it's represented by nothing, that means it appears as just a generic box; like a Note that it does not display its content, in browsers that support the Content may be provided inside the
video element. User agents should not
show this content to the user; it is
intended for older Web browsers which
do not support video, so that legacy
video plugins can be tried, or to show
text to the users of these older
browsers informing them of how to
access the video contents.
这篇关于没有源代码的HTML5视频标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
元素的readyState属性为
,或者 HAVE_NOTHING
或
HAVE_METADATA
,但没有视频数据已经获得
),视频
元素代表海报
帧,或者没有任何内容。
div
,它可以是样式的,但没有自己的内在显示,尽管它的宽度和高度由它的宽度指定
和 height
属性。 例如:
<!DOCTYPE html>
< video width = 100 height = 100
style =border-width:1px; border-color:black; border-style:solid;
background:green>
foobar
< / video>
视频的浏览器中显示其内容
标签。除了源
元素之外,视频
标记中的内容仅用于旧版浏览器不支持视频
元素:
视频元素。用户代理不应
向用户显示此内容;对于旧版Web浏览器而言,它是
,其中
不支持视频,因此可以尝试传统的
视频插件,或向这些较旧的$ b的用户显示
文本$ b浏览器通知他们如何
访问视频内容。
src
attribute or source
element:
If the
element has a src attribute:
transparent, but with no media element
descendants.
If the element does not
have a src attribute: one or more
source elements, then, transparent,
but with no media element
descendants.src
attribute or a source
child element. But both the Validator.nu and the W3C Validator seem to think this is a valid document:<!DOCTYPE html>
<title>Video test</title>
<video></video>
HAVE_NOTHING
HAVE_NOTHING
(numeric value 0)
No information regarding the media
resource is available. No data for the
current playback position is
available. Media elements whose
networkState attribute is
NETWORK_EMPTY
are always in the
HAVE_NOTHING
state.
HAVE_NOTHING
, or
HAVE_METADATA
but no video data has
yet been obtained at all), the video
element represents either the poster
frame, or nothing.div
, that can be styled but has no intrinsic display of its own, though it will be the width and height specified by its width
and height
attributes. For example:<!DOCTYPE html>
<video width=100 height=100
style="border-width: 1px; border-color:black; border-style: solid;
background: green">
foobar
</video>
video
tag. Content within the video
tag, other than the source
elements, is intended to be fallback content displayed only by older browsers that don't support the video
element: