+ Reply to Thread
Results 1 to 2 of 2

Thread: How to cancel Redirect ?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    7

    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 :
    Code:
    <script type="text/javascript">
    
    if (screen.width <= 640) {
        window.location = "http://m.mywebsite.com";
    }
    
    </script>
    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
    Posts
    36
    You can actually add a parameter on your link to force the view to be main or mobile.
    For example :
    Code:
    <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.

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

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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