자바 스크립트에서 브라우저 간 플래시 감지
브라우저가 임베디드 플래시 콘텐츠를 표시 할 수 있는지 감지하기 위해 IE / Firefox에서 안정적으로 작동 할 수있는 스크립트 예제가있는 사람이 있습니까? 나는 그것이 불가능하다는 것을 100 % 알고 있기 때문에 확실하게 말한다.
SWFObject 는 매우 안정적입니다. 나는 꽤 오랫동안 문제없이 그것을 사용했습니다.
나는 Max Stewart에 동의합니다 . SWFObject 는 갈 길입니다. 코드 예제로 그의 대답을 보완하고 싶습니다. 시작해야합니다.
swfobject.js
파일 을 포함했는지 확인하십시오 ( 여기에서 가져 오기 ).
<script type="text/javascript" src="swfobject.js"></script>
그런 다음 다음과 같이 사용하십시오.
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");
}
"9.0.115"를 필요한 최소 플래시 버전으로 바꿉니다. 저는 9.0.115를 예로 선택했습니다. 264 지원을 추가 한 버전이기 때문입니다.
방문자에게 플래시가없는 경우 "0.0.0"의 플래시 버전을보고하므로 플래시가 전혀 없는지 알고 싶다면 다음을 사용하세요.
if(swfobject.hasFlashPlayerVersion("1"))
{
alert("You have flash!");
}
else
{
alert("You do not flash :-(");
}
나는 이것이 오래된 게시물이라는 것을 알고 있지만 한동안 찾고 있었지만 아무것도 찾지 못했습니다. 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>
클로저 컴파일러 를 사용하여 작은 브라우저 간 플래시 감지를 생성 할 수 있습니다 .
// ==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');
}
다음 "컴파일 된"코드가 생성됩니다.
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");
내가 사용한 최소 버전 (버전을 확인하지 않고 Flash 플러그인 만) :
var hasFlash = function() {
return (typeof navigator.plugins == "undefined" || navigator.plugins.length == 0) ? !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) : navigator.plugins["Shockwave Flash"];
};
Carl Yestrau의 JavaScript Flash Detection Library는 다음과 같습니다.
http://www.featureblend.com/javascript-flash-detection-library.html
... 당신이 찾고있는 것일 수 있습니다.
어도비의 플래시 플레이어 감지 키트가 여기에 도움이 될 수 있습니까?
http://www.adobe.com/products/flashplayer/download/detection_kit/
웹 문서 내에서 Flash를 감지하고 포함하는 것은 놀랍도록 어려운 작업입니다.
저는 SWFObject와 Adobe의 솔루션 모두에서 생성 된 품질 및 비표준 준수 마크 업에 매우 실망했습니다. 또한 테스트 결과 Adobe의 자동 업데이트 프로그램이 일관성이없고 신뢰할 수없는 것으로 나타났습니다.
JavaScript Flash Detection Library (Flash Detect) 및 JavaScript Flash HTML Generator Library (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>
다음과 같은 대안이 있습니다. swfobject.getFlashPlayerVersion();
View the source at http://whatsmy.browsersize.com (lines 14-120).
Here is the abstracted cross browser code on jsbin for flash detection only, works on: FF/IE/Safari/Opera/Chrome.
what about:
var hasFlash = function() {
var flash = false;
try{
if(new ActiveXObject('ShockwaveFlash.ShockwaveFlash')){
flash=true;
}
}catch(e){
if(navigator.mimeTypes ['application/x-shockwave-flash'] !== undefined){
flash=true;
}
}
return flash;
};
If you are interested in a pure Javascript solution, here is the one that I copy from Brett:
function detectflash(){
if (navigator.plugins != null && navigator.plugins.length > 0){
return navigator.plugins["Shockwave Flash"] && true;
}
if(~navigator.userAgent.toLowerCase().indexOf("webtv")){
return true;
}
if(~navigator.appVersion.indexOf("MSIE") && !~navigator.userAgent.indexOf("Opera")){
try{
return new ActiveXObject("ShockwaveFlash.ShockwaveFlash") && true;
} catch(e){}
}
return false;
}
If you just wanted to check whether flash is enabled, this should be enough.
function testFlash() {
var support = false;
//IE only
if("ActiveXObject" in window) {
try{
support = !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
}catch(e){
support = false;
}
//W3C, better support in legacy browser
} else {
support = !!navigator.mimeTypes['application/x-shockwave-flash'];
}
return support;
}
Note: avoid checking enabledPlugin, some mobile browser has tap-to-enable flash plugin, and will trigger false negative.
To create a Flash object standart-compliant (with JavaScript however), I recommend you take a look at
Unobtrusive Flash Objects (UFO)
http://www.bobbyvandersluis.com/ufo/index.html
Have created a small .swf
which redirects. If the browser is flash enabled it will redirect.
package com.play48.modules.standalone.util;
import flash.net.URLRequest;
class Redirect {
static function main() {
flash.Lib.getURL(new URLRequest("http://play48.com/flash.html"), "_self");
}
}
Using Google Closure compiler goog.require('goog.userAgent.flash') library I created this 2 functions.
boolean hasFlash()
Returns if browser has flash.
function hasFlash(){
var b = !1;
function c(a) {if (a = a.match(/[\d]+/g)) {a.length = 3;}}
(function() {
if (navigator.plugins && navigator.plugins.length) {
var a = navigator.plugins["Shockwave Flash"];
if (a && (b = !0, a.description)) {c(a.description);return;}
if (navigator.plugins["Shockwave Flash 2.0"]) {b = !0;return;}
}
if (navigator.mimeTypes && navigator.mimeTypes.length && (a = navigator.mimeTypes["application/x-shockwave-flash"], b = !(!a || !a.enabledPlugin))) {c(a.enabledPlugin.description);return;}
if ("undefined" != typeof ActiveXObject) {
try {
var d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");b = !0;c(d.GetVariable("$version"));return;
} catch (e) {}
try {
d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");b = !0;
return;
} catch (e) {}
try {
d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), b = !0, c(d.GetVariable("$version"));
} catch (e) {}
}
})();
return b;
}
boolean isFlashVersion(version)
Returns if the flash version is greater than provided version
function isFlashVersion(version) {
var e = String.prototype.trim ? function(a) {return a.trim()} : function(a) {return /^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(a)[1]};
function f(a, b) {return a < b ? -1 : a > b ? 1 : 0};
var h = !1,l = "";
function m(a) {a = a.match(/[\d]+/g);if (!a) {return ""}a.length = 3;return a.join(".")}
(function() {
if (navigator.plugins && navigator.plugins.length) {
var a = navigator.plugins["Shockwave Flash"];
if (a && (h = !0, a.description)) {l = m(a.description);return}
if (navigator.plugins["Shockwave Flash 2.0"]) {h = !0;l = "2.0.0.11";return}
}
if (navigator.mimeTypes && navigator.mimeTypes.length && (a = navigator.mimeTypes["application/x-shockwave-flash"], h = !(!a || !a.enabledPlugin))) {l = m(a.enabledPlugin.description);return}
if ("undefined" != typeof ActiveXObject) {
try {
var b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");h = !0;l = m(b.GetVariable("$version"));return
} catch (g) {}
try {
b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");h = !0;l = "6.0.21";return
} catch (g) {}
try {
b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), h = !0, l = m(b.GetVariable("$version"))
} catch (g) {}
}
})();
var n = l;
return (function(a) {
var b = 0,g = e(String(n)).split(".");
a = e(String(a)).split(".");
for (var p = Math.max(g.length, a.length), k = 0; 0 == b && k < p; k++) {
var c = g[k] || "",d = a[k] || "";
do {
c = /(\d*)(\D*)(.*)/.exec(c) || ["", "", "", ""];d = /(\d*)(\D*)(.*)/.exec(d) || ["", "", "", ""];
if (0 == c[0].length && 0 == d[0].length) {break}
b = f(0 == c[1].length ? 0 : parseInt(c[1], 10), 0 == d[1].length ? 0 : parseInt(d[1], 10)) || f(0 == c[2].length, 0 == d[2].length) || f(c[2], d[2]);c = c[3];d = d[3]
} while (0 == b);
}
return 0 <= b
})(version)
}
참고URL : https://stackoverflow.com/questions/159261/cross-browser-flash-detection-in-javascript
'Programing' 카테고리의 다른 글
급여 테이블에서 세 번째 또는 n 번째 최대 급여를 찾는 방법은 무엇입니까? (0) | 2020.08.27 |
---|---|
Android는 뷰 사이에 수평선을 그립니다. (0) | 2020.08.27 |
MVC Razor 뷰 중첩 foreach의 모델 (0) | 2020.08.27 |
트위터 부트 스트랩 버튼 스타일링 (0) | 2020.08.27 |
python pandas는 중복 열을 제거합니다. (0) | 2020.08.27 |