Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 19 hours ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 4 days ago

Designer, software engineer and a content writer. Working as a web developer in a local company and studying to become a graphic designer.

Papermashup

Understanding your browsers plugins

Understanding the use of the Navigator JavaScript method to detect supported actions on a web page

HiraHira

Browser plugins help you view PDF documents, Flash content and can also make audio and video files work better. Have you ever needed to use a certain plugin in your code but you are not sure whether it is installed in your browser? In this tutorial we cover a simple JavaScript snippet that helps you find the plugins installed in your browser and also cover how you can use that plugin to display the media you want.

The navigator object in JavaScript which is commonly used for animations, also includes an array object called plugins. This array maintains the record of all the plugins installed in a browser. The information stored in the array includes the name of plugin, the path of the executable file that was needed to install the plugin, a brief description and all the mime types supported by that certain plugin.

To find the list of plugins installed in your browser, here is a simple JavaScript snippet that can help you do that.



for (count=0; count < navigator.plugins.length; count++) { document.write("

");
document.write(navigator.plugins[count].name);
document.write("

");
document.write(navigator.plugins[count].filename);
document.write("

");
document.write(navigator.plugins[count].description);
document.write("

");

}

Once you have found that your browser supports the required plugin, you can use that plugin to display the media file that you want using the following as an example.


var plugin = navigator.mimeTypes["video/avi"];

if (plugin){
document.write("");
}else{
document.write("");
}

What this code snippet does is to first check whether or not the required mime type is supported by the plugins installed in your browser. We check for the video/avi files. If this mime type is installed we will display the avi file but otherwise we will display a gif image instead.

You can find out more information about the navigator object array at developer.mozilla.org.

I hope this tutorial proves useful to you.

Designer, software engineer and a content writer. Working as a web developer in a local company and studying to become a graphic designer.

    Comments 0
    There are currently no comments.