Take the 2-minute tour ×

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 language="javascript"> 
if (mobile) ||  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) {

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>
<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...

share|improve this question
Your way of commenting the JavaScript is suspect. I doubt it will make a difference, but try this pattern: <script type="text/javascript">//<![CDATA[ javascript-code-here new-line //]]></script>. (In other words, replace the <!-- ... //--> commenting with a CDATA start/end sequence, as recommended here.) –  Ted Hopp Mar 29 '13 at 3:35
add comment

1 Answer

up vote 1 down vote accepted

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:




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://

share|improve this answer
add comment

Your Answer


