Tuesday 17 June 2014

Add Html5 Tags in Internet Explorer 8

Introduction:

Html5 is popular language but some of older browser such as IE8,IE7 and lower not supported Html5.

Html5 introduce some new elements such as header,section but older browser doesn't know about these tags then it can't generate them so you will find that in IE8 or lower your website will be without any styles.

Here is solution for add Html5 tags in IE8 and lower.

First we have to detect IE Version and then we have to create elements which is added by Html5.

Code:


var userAgent = navigator.userAgent.toLowerCase();
// Test if the browser is IE and check the version number is lower than 9
if (/msie/.test(userAgent) && 
    parseFloat((userAgent.match(/.*(?:rv|ie)[\/: ](.+?)([ \);]|$)/) || [])[1]) < 9) {
 
         document.createElement('header');
         document.createElement('section');
         document.createElement('article');
         document.createElement('aside');
         document.createElement('nav');
         document.createElement('footer');
}


Copy the following code at top of page.

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->



Detect mobile device using JavaScript

Introduction:

Here i will explain how to detect mobile device using JavaScript

This is simplest way to detect mobile device.

Code:

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
 // some code..
}