+ Reply to Thread
Results 1 to 2 of 2

Thread: How to cancel Redirect ?

  1. #1
    Junior Member
    Join Date
    Jun 2012

    How to cancel Redirect ?

    I have added a mobile version to my website and i had to detect the screen size of the browser to determine whether it is a mobile
    or computer device.

    Here is my code :
    <script type="text/javascript">
    if (screen.width <= 640) {
        window.location = "http://m.mywebsite.com";
    Now , if user is using a mobile and he is now redirected to the m.mywebsite.com.
    I have provided a link on my mobile version website to go to the main website , but what happens is
    user can be redirected back to the mobile version website because of the javascript method.
    Now how to overcome that ?

  2. #2
    Junior Member
    Join Date
    May 2012
    You can actually add a parameter on your link to force the view to be main or mobile.
    For example :
    <a href="http://www.mywebsite.com?view=main">Main site</a>
    So to do that , you need to do 2 steps :
    1- read the querystring
    2- check if it is main or not.

    function getParameterByName(name) {
        var match = RegExp('[?&]' + name + '=([^&]*)')
        return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
    if (screen.width <= 800 && getParameterByName('view') != 'main') {
        window.location = "http://m.domain.com";

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts