Skip to content

Instantly share code, notes, and snippets.

@rajeshsegu
Created August 18, 2012 20:49
Show Gist options
  • Save rajeshsegu/3389800 to your computer and use it in GitHub Desktop.
Save rajeshsegu/3389800 to your computer and use it in GitHub Desktop.
jQuery plugin to detect platform
/*jQuery plugin to detect browser platform */
//Idea is extend this to support various browser related environment variables.
(function($) {
var BrowserEnvironment = {
//init browser environment
init: function () {
//Find platform
this.platform = this.detect(this.osData);
},
//Detects and populates the environment
detect: function(data){
var env = {}, prop,
length = data.length;
for(var i=0; i< data.length; i++ ){
prop = data[i];
env[prop.attribute] = ( prop.property.indexOf(prop.subString) != -1 )
}
return env;
},
//Populate as we need
osData : [
{
property: navigator.platform,
subString: "Win",
attribute: "isWindows"
},
{
property: navigator.platform,
subString: "Mac",
attribute: "isMac"
},
{
property: navigator.platform,
subString: "Linux",
attribute: "isLinux"
},
{
property: navigator.platform,
subString: "iPad",
attribute: "isiPad"
}
]
};
//Start browser environment detection
BrowserEnvironment.init();
//Make platform accessible via jQuery
$.platform = BrowserEnvironment.platform;
})(jQuery);
@revathinandha
Copy link

<title>First jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("p").css("background-color", "pink"); }); </script>

This is first paragraph.

This is second paragraph.

This is third paragraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment