Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a mobile version of the site but one confusing thing is becoming a hurdle for me. I have pasted some javascript code on main website to redirect the mobile users to mobile website but its not working properley so what can i do.
Please Details with example.
Posted

JavaScript
<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobile.html";
}
//-->
</script>


"mobile.html" would be replaced with the location of wherever your mobile version resides. This technique could be adapted to load an alternate stylesheet as well.

For iPhones/iPods Specifically
JavaScript
<script language="javascript">
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   location.replace("http://url-to-send-them/iphone.html");
}
-->
</script>
 
Share this answer
 
You can detect the mobiles on the server side if you are using ASP.NET.
Have a look at this project on CodePlex its open source and supports maximum devices.
http://51degrees.codeplex.com/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900