Archive for the ‘Javascript & Jquery’ Category

http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaScript-Generators

Advertisements

There is a very simple way to detect whether a user is viewing your website through his mobile device and if needed create a pop-up or redirect him instantly to your site’s mobile version.

Using the user’s agent you can find whether it is some kind of mobile device and then redirect him using window.location to the url you want. Credit goes mostly to here

In this example, I am searching for the keys “iphone” or “ipod”, in lower case just to be sure, and create a popup prompting the user to visit one of two possible urls. If you like only to visit one when clicking ok, just remove the else part of the following code and when cancel is clicked the popup will simply vanish without any redirection being made.

if(navigator.userAgent.toLowerCase().indexOf(‘iphone’)!=-1)|| (navigator.userAgent.toLowerCase().indexOf(‘ipod’)!=-1){

var question = confirm(‘Would you like to see the iphone version of our site?’);
if (question){ window.location = ‘YourIphoneSiteUrl’; }
}

else {  window.location = ‘SomeOtherSiteUrl’; }

}