Created
April 30, 2012 19:31
-
-
Save gudbergur/2561877 to your computer and use it in GitHub Desktop.
Add CSS class to mobile browsers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simple javascript that adds "mobile" class to body tag when visited by mobile browsers but "desktop" otherwise. | |
Instructions: Add <script src="<path to>mobilecss.js"></script> before </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(n,d,w){s = n.userAgent;if (s.match(/iPhone/i)||s.match(/iPad/i)||s.match(/Android/i)||s.match(/IEMobile/i)||s.match(/Blackberry/i)||s.match(/WebOs/i)){w.is_mobile=true;d.body.className+="mobile";}else{w.is_mobile=false;d.body.className+="desktop"}})(navigator,document,window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment