Kako proveriti da li je određeni plugin instaliran u browseru

Započeo holodoc, 26.07.2009, 22:21

« prethodna tema - sledeća tema »
Idi dole

holodoc

26.07.2009, 22:21 Poslednja Izmena: 26.07.2009, 22:25 od holodoc
Evo jedne kratke skriptice koja proverava da li je određeni plugin kao što su recimo Flash ili Java instalirani u browseru. Važi samo za Firefox i ostale "non-IE" browsere. Usput skripta izlistava sve instalirane pluginove u browseru.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Player test page</title>
<script type="text/javascript">
function checkPlugin(pluginName){
var pluginFound = false;
var pluginsCount = navigator.plugins.length;
for(var i=0; i < pluginsCount; i++) {
if(navigator.plugins[i].name == pluginName){
pluginFound = true;
break;
}
}
if(!pluginFound){
alert('The required plugin "' + pluginName + '" was not found!');
}
}
window.onload = function(){
checkPlugin('Shockwave Flash');
}
</script>
</head>
<body>
Ovaj kod dole se u stvari može naći na <strong><a href="https://developer.mozilla.org/en/DOM/window.navigator.plugins">Mozilla Developer Centru</a>.</strong><hr />
<script type="text/javascript">
var L = navigator.plugins.length;
document.write(L.toString().bold() + " Plugin(s)".bold());
document.write("<br>");
document.write("Name | Filename | description".bold());
document.write("<br>");
for(var i=0; i<L; i++) {
document.write(navigator.plugins[i].name);
document.write(" | ");
document.write(navigator.plugins[i].filename);
document.write(" | ");
document.write(navigator.plugins[i].description);
document.write("<br>");
   }
</script>

</body>
</html>

<?php
abstract class Ignorance extends Stupidity implements Unavoidable 
    private function 
__construct(){
        
parent::__destruct();
    }; 

// EOF -> life.php

holodoc

Malo sam se poigrao da detekcija plugina radi i u Internet Exploreru i evo konačnog rezultata. Da bi skripta funkcionisala potrebno je da uz nju bude prikačen i fajl BrowserDetect.class.js čisto zarad identifikacije browsera. BrowserDetect klasa nije moje delo već je preuzeta u celosti sa Quirksmode.com (http://www.quirksmode.org/js/detect.html) pošto se radi o veoma kvalitetnoj skripti.

Ovde se konkretno radi o proveri da li je u okviru browsera instaliran Flash. Za Internet Explorer je u okviru promenjljive IEPluginName porebno unesti puno kvalifikovano ime ActiveX komponente kao što je to u slučaju Flasha ShockwaveFlash.ShockwaveFlash.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>- Browser plug-in detect page</title>

<!-- The following line as well as the associated BrowserDetect.class.js file must be included here -->

<script type="text/javascript" src="BrowserDetect.class.js"></script>

<script type="text/javascript">

var IEPluginName = 'ShockwaveFlash.ShockwaveFlash'; //Internet Explorer ActiveX server qualified plugin name

var pluginName = 'Shockwave Flash'; //All the rest use this non ActiveX plugin name

var pluginFound = false; // On nonIE browsers it contains the result of the plugin search [true/false]

var detectionMessage; //message to display inside the page body

var plugin = false; //ActiveX instatiated plugin object



if(BrowserDetect.browser == "Explorer"){ //Is it the infamous Explorer?

try {

var plugin = new ActiveXObject(IEPluginName); //try to instantiate an ActiveX plugin object

} catch(e){ //nope... there is no plugin with that name!

detectionMessage = "The requested plugin \"" + IEPluginName + "\" was not found!";

alert(detectionMessage);

}

if(plugin){ //plugin found

detectionMessage = "Congratulations! The requested plugin " + IEPluginName + " is installed!";

}

} else { //all the rest of the browsers

var pluginsCount = navigator.plugins.length; //how many plugins are installed?

for(var i=0; i < pluginsCount; i++) { //for each and every one of them

  if(navigator.plugins[i].name == pluginName){ //compare its name with the requested plugin name

          pluginFound = true; //if found set the pluginFound to true

          break; //and exit the search loop

}

      }

    if(!pluginFound){ //plugin not found

detectionMessage = "The requested plugin \"" + pluginName + "\" was not found!";

alert(detectionMessage);

    } else {

detectionMessage = "Congratulations! The requested plugin \"" + pluginName + "\" is installed!";

}

}

</script>

<style type="text/css">

#detect_result {

color: #4c4c4c;

}



#detect_header {

font-family: Arial, Helvetica, sans-serif;

font-size: 12px;

color: #666666;

}



#detect_header h5 {

margin: 0;

padding: 0;

line-height: normal;

font-size: 18px;

}

</style>

</head>

<body>

<div id="detect_header">

  <h5>Browser plug-in detection page</h5>

  <p id="detect_result">Plugin detection in progress...<script type="text/javascript">document.write(detectionMessage);</script></p>

</div>

</div>

</body>

</html>

var BrowserDetect = {

init: function () {

this.browser = this.searchString(this.dataBrowser) || "An unknown browser";

this.version = this.searchVersion(navigator.userAgent)

|| this.searchVersion(navigator.appVersion)

|| "an unknown version";

this.OS = this.searchString(this.dataOS) || "an unknown OS";

},

searchString: function (data) {

for (var i=0;i<data.length;i++) {

var dataString = data[i].string;

var dataProp = data[i].prop;

this.versionSearchString = data[i].versionSearch || data[i].identity;

if (dataString) {

if (dataString.indexOf(data[i].subString) != -1)

return data[i].identity;

}

else if (dataProp)

return data[i].identity;

}

},

searchVersion: function (dataString) {

var index = dataString.indexOf(this.versionSearchString);

if (index == -1) return;

return parseFloat(dataString.substring(index+this.versionSearchString.length+1));

},

dataBrowser: [

{

string: navigator.userAgent,

subString: "Chrome",

identity: "Chrome"

},

{ string: navigator.userAgent,

subString: "OmniWeb",

versionSearch: "OmniWeb/",

identity: "OmniWeb"

},

{

string: navigator.vendor,

subString: "Apple",

identity: "Safari",

versionSearch: "Version"

},

{

prop: window.opera,

identity: "Opera"

},

{

string: navigator.vendor,

subString: "iCab",

identity: "iCab"

},

{

string: navigator.vendor,

subString: "KDE",

identity: "Konqueror"

},

{

string: navigator.userAgent,

subString: "Firefox",

identity: "Firefox"

},

{

string: navigator.vendor,

subString: "Camino",

identity: "Camino"

},

{ // for newer Netscapes (6+)

string: navigator.userAgent,

subString: "Netscape",

identity: "Netscape"

},

{

string: navigator.userAgent,

subString: "MSIE",

identity: "Explorer",

versionSearch: "MSIE"

},

{

string: navigator.userAgent,

subString: "Gecko",

identity: "Mozilla",

versionSearch: "rv"

},

{ // for older Netscapes (4-)

string: navigator.userAgent,

subString: "Mozilla",

identity: "Netscape",

versionSearch: "Mozilla"

}

],

dataOS : [

{

string: navigator.platform,

subString: "Win",

identity: "Windows"

},

{

string: navigator.platform,

subString: "Mac",

identity: "Mac"

},

{

   string: navigator.userAgent,

   subString: "iPhone",

   identity: "iPhone/iPod"

    },

{

string: navigator.platform,

subString: "Linux",

identity: "Linux"

}

]



};

BrowserDetect.init();
<?php
abstract class Ignorance extends Stupidity implements Unavoidable 
    private function 
__construct(){
        
parent::__destruct();
    }; 

// EOF -> life.php

Idi gore