Reputation: 25058
I am using this to redirect to a mobile version of a webpage (it is not in a sub domain)
<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "http://www.site.com/mobile/";
}
//-->
</script>
<script language="javascript">
<!--
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) {
location.replace("http://www.site.com/mobile/");
}
//-->
</script>
But when I access from a mobile I get an error that server is not found?
Here is the header of the mobile version
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<link rel="apple-touch-icon" sizes="114x114" href="images/icontwo.png">
<link rel="apple-touch-startup-image" href="images/startup.png" />
What could be causing this?, If I enter directly it seems to work...
Upvotes: 0
Views: 419
Reputation: 38253
Just to be safe I would use window.location.href
because semantically the document
object is referring to the DOM document or the HTML elements on the page. Also, some browsers only use window.location.href
Also, you seem to be using two redirects:
document.location = "http://www.site.com/mobile/";
AND
location.replace("http://www.site.com/mobile/");
which may cause issues. location.replace
actually destroys the back button capability too which may cause some weird effects not to mention agitated users.
Also, make sure you're not coming onto the site with https://
Upvotes: 1