Welcome to the in5 Answer Exchange! This a place to get answers about in5 (InDesign to HTML5) and make requests.
+1 vote

What I want to do is create a file for web and one as a web app (for use on mobile) and add code to each that will detect what device the user is viewing it on. If the user is viewing the web link on a mobile device I want it to detect that and redirect them to the web app (mobile version). If the user is viewing the mobile link from a desktop I want it to detect that and redirect them to the web version. Now i'm no coder so I've googled this and found a few options that didn't work like:

<script type="text/javascript">
if (screen.width >= 699) {
}
</script>
 
or
 
<script type="text/javascript">
if((navigator.userAgent.match(/iPhone/i)) || 
 (navigator.userAgent.match(/iPod/i))) {
   if (document.cookie.indexOf("iphone_redirect=false") == -1) window.location = "http://www.jayack.com/mobile/";
}
</script>
 
Has anyone done this before? Can anyone please point me in the right direction or assist that would be much appreciated. Thanks in advance  

 

in how_to by (200 points)
  

1 Answer

0 votes
 
Best answer

I figured it out, first off I did not add any code within the in5 export window. I exported normally and did not edit the code it exported. I used the method presented on http://detectmobilebrowsers.mobi I added their mobile_device_detect.php file on the same level as the index.html along with a second php file with the following code in it

<?php
 
 
require_once('mobile_device_detect.php');
$mobile = mobile_device_detect();
 
// redirect all mobiles to mobile site and all other browsers to desktop site
if($mobile==true){
  header('Location:http://yourmobilesite.com/');
}else{
  header('Location:http://yourdesktopsite.com/');
}
exit;
 
?>
 
So now when a user has the desktop link and is viewing it from a mobile device it will automatically redirect them to web app build. If someone has the web app link and tries to view it from a desktop it automatically redirects them to the regular web build. 
 
Any questions let me know 

 

by (200 points)
selected by
Nice! Glad you found a solution that works for you. :-)