Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7884685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:52:00+00:00 2026-06-03T04:52:00+00:00

I have a mobile site but I need a script to redirect a user

  • 0

I have a mobile site but I need a script to redirect a user to it if they are on a mobile device.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:52:02+00:00Added an answer on June 3, 2026 at 4:52 am

    There are several ways you can do it, but detecting the screen size is a good way to do that. Note that the screen width is independent of the browser window size.

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

    You can also match specific devices like the iPhone or iPod by the User Agent string.

    <script language=javascript>
    <!--
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
       location.replace("http://url-to-send-them/iphone.html");
    }
    -->
    </script>
    

    Important Caveat

    While this works, it’s also very annoying to get redirected to the mobile site’s front page when you’re trying to visit a particular page. For example, when you follow a link from Facebook trying to access an article, if the site redirects you to the front page of the mobile version of the site, it’s infuriating and very unhelpful! Chances are, they’ll never try hard enough to find the content.

    paulsm4 is correct that using CSS to serve a mobile layout for your site at the same URL instead of redirecting is a much more desirable solution. However if that’s not an option, the next best thing is to redirect to the matching URL for the mobile version of the site.

    For example, if you just have a different subdomain for your mobile site, then you can use Javascript to redirect to the correct page of the mobile version:

    <script type="text/javascript">
    <!--
    // Full URL:   http://example.com/articles/1
    // Mobile URL: http://mobile.example.com/articles/1
    if (screen.width <= 699) {
      // Redirect to the same page on the mobile site
      document.location.host = "mobile." + document.location.host;
    }
    //-->
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mobile site and I'd like to redirect users to the domain.mobi
I've posted similar question but no response. I have a jQuery Mobile site and
I have a mobile site running with jQuery Mobile. I want to have standard
I have a public desktop site, a public mobile site, and a private intranet
I have linked a form from campaign monitor to a mobile site and I
I am developing a site for mob using jquery mobile. I have a content
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic
I'm trying to upgrade a javascript site to a Jquery Mobile site. I need
I'm about to start developing a site that will have a regular and mobile
While I have a successful method of getting users from our mobile site to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.