2

我正在尝试使用 api 加载 youtube 视频。我复制并粘贴了示例代码。但是当兼容模式打开时,我在 Internet Explorer 8 中遇到错误,我想强制使用 8 模式。

这是错误:

Message: 'JSON' is undefined
Line: 33
Char: 136
Code: 0
URI: http://s.ytimg.com/yt/jsbin/www-embed_core_module-vflDULhso.js

这是具有示例代码+强制模式8的html:

http://cdn.radicalislam.org/enriched/test.html

4

2 回答 2

2

YouTube iframe API 依赖于一些仅由 IE8+ 在标准模式下提供的功能。

这些在此处的“要求”下有所提及:

https://developers.google.com/youtube/iframe_api_reference

特别是(除了您提到的 JSON 依赖项之外)对 postMessage API 有一个要求 - 这是 JavaScript 库无法提供的。最终结果是,YouTube iframe API 不能在兼容模式下的 IE8 上使用,也不能被任何其他不支持 postMessage 的浏览器使用。

虽然 IE8 确实支持标准模式下的要求,但降到兼容模式会破坏这种行为。

查看您发布的链接后,您似乎已经添加了一个文档类型来强制标准模式,因为您发布了这个 - 这是否解决了问题?

于 2012-09-17T12:00:49.850 回答
1

The error is quite surprising as AFAIK JSON support is no longer a problem as almost all browser support it now (http://caniuse.com/json). However it seems that JSON is not supported in your case, so you will need a polyfill such as json2. To load it Modernizr use this:

Modernizr.load({
  test: !!window.JSON && !!JSON.parse,
  nope: 'json2.js'
});

Update: I overlook a note at the bottom of the Can I Use page; to have JSON support in IE8 you will have to use HTML5 doctype as <!DOCTYPE html> in the top of your HTML.

于 2012-09-15T09:48:40.493 回答