detect mobile device using javascript

The code I use:

mobile和desktop用不同的navigation bar:

$(document).ready(function(){
$(“#mobile_nav”).hide();
var ua=navigator.userAgent
var isTouchScreen = ‘createTouch’ in document || screen.width <= 699 ||
ua.match(/(iPhone|iPod|iPad)/) || ua.match(/BlackBerry/) ||
ua.match(/Android/);

if( isTouchScreen ){
$(“#main_nav”).hide();
$(“#mobile_nav”).show();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s