kd7*_*kd7 94 javascript flash cross-browser
有没有人有一个脚本的例子可以在IE/Firefox中可靠地工作,以检测浏览器是否能够显示嵌入式Flash内容.我说得可靠,因为我知道它不可能100%的时间.
And*_*ley 109
我同意Max Stewart的观点. SWFObject是要走的路.我想用代码示例来补充他的答案.这应该让你开始:
确保您已包含该swfobject.js文件(在此处获取):
<script type="text/javascript" src="swfobject.js"></script>
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它:
if(swfobject.hasFlashPlayerVersion("9.0.115"))
{
alert("You have the minimum required flash version (or newer)");
}
else
{
alert("You do not have the minimum required flash version");
}
Run Code Online (Sandbox Code Playgroud)
将"9.0.115"替换为您需要的最低闪存版本.我选择9.0.115作为示例,因为这是添加了h.264支持的版本.
如果访问者没有闪存,它将报告闪存版本为"0.0.0",因此如果您只想知道他们是否有闪存,请使用:
if(swfobject.hasFlashPlayerVersion("1"))
{
alert("You have flash!");
}
else
{
alert("You do not flash :-(");
}
Run Code Online (Sandbox Code Playgroud)
Max*_*art 93
SWFObject非常可靠.我已经使用它很长一段时间了.
小智 36
我知道这是一个老帖子,但我一直在寻找一段时间,但没有找到任何东西.
我已经实现了JavaScript Flash Detection Library.它运作良好,并记录下来以便快速使用.它花了我2分钟.这是我在标题中写的代码:
<script src="Scripts/flash_detect.js"></script>
<script type="text/javascript">
if (!FlashDetect.installed) {
alert("Flash is required to enjoy this site.");
} else {
alert("Flash is installed on your Web browser.");
}
</script>
Run Code Online (Sandbox Code Playgroud)
ste*_*ewe 32
您可以使用闭包编译器生成一个小的跨浏览器闪存检测:
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @formatting pretty_print
// @use_closure_library true
// ==/ClosureCompiler==
// ADD YOUR CODE HERE
goog.require('goog.userAgent.flash');
if (goog.userAgent.flash.HAS_FLASH) {
alert('flash version: '+goog.userAgent.flash.VERSION);
}else{
alert('no flash found');
}
Run Code Online (Sandbox Code Playgroud)
这导致以下"编译"代码:
var a = !1,
b = "";
function c(d) {
d = d.match(/[\d]+/g);
d.length = 3;
return d.join(".")
}
if (navigator.plugins && navigator.plugins.length) {
var e = navigator.plugins["Shockwave Flash"];
e && (a = !0, e.description && (b = c(e.description)));
navigator.plugins["Shockwave Flash 2.0"] && (a = !0, b = "2.0.0.11")
} else {
if (navigator.mimeTypes && navigator.mimeTypes.length) {
var f = navigator.mimeTypes["application/x-shockwave-flash"];
(a = f && f.enabledPlugin) && (b = c(f.enabledPlugin.description))
} else {
try {
var g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"),
a = !0,
b = c(g.GetVariable("$version"))
} catch (h) {
try {
g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"), a = !0, b = "6.0.21"
} catch (i) {
try {
g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), a = !0, b = c(g.GetVariable("$version"))
} catch (j) {}
}
}
}
}
var k = b;
a ? alert("flash version: " + k) : alert("no flash found");
Run Code Online (Sandbox Code Playgroud)
Tom*_*ero 22
我用过的最低版本(不检查版本,只是Flash插件):
var hasFlash = function() {
return (typeof navigator.plugins == "undefined" || navigator.plugins.length == 0) ? !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) : navigator.plugins["Shockwave Flash"];
};
Run Code Online (Sandbox Code Playgroud)
Carl Yestrau的JavaScript Flash Detection Library,在这里:
http://www.featureblend.com/javascript-flash-detection-library.html
......可能就是你要找的东西.
也许adobe的flash播放器检测套件在这里有用吗?
http://www.adobe.com/products/flashplayer/download/detection_kit/
小智 5
在Web文档中检测和嵌入Flash是一项非常困难的任务.
我对SWFObject和Adobe解决方案生成的质量和非标准兼容标记感到非常失望.此外,我的测试发现Adobe的自动更新程序不一致且不可靠.
JavaScript Flash检测库(Flash检测)和JavaScript Flash HTML生成器库(Flash TML)是一种易读,可维护且符合标准的标记解决方案.
- "卢克读了源!"
一个线性变量的代码isFlashExists:
<script type='text/javascript'
src='//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'> </script>
<script type='text/javascript'>
var isFlashExists = swfobject.hasFlashPlayerVersion('1') ? true : false ;
if (isFlashExists) {
alert ('flash exists');
} else {
alert ('NO flash');
}
</script>
Run Code Online (Sandbox Code Playgroud)
请注意,还有一个类似的替代方案:swfobject.getFlashPlayerVersion();