Redirection script mobile site

10 replies
Can anyone shed light why certain servers will not let a simple javascript work and yet a redirect service works fine.

So this worts great on one site but not on another

<script language="javascript">
var width = screen.width;
if (width < 600) {window.location='http://yourdomain.com/mobile.php'}
</script>

Have you got any better scripts and does the spacing : ; make any difference.

Quentin
#mobile #redirection #script #site
  • Profile picture of the author Adrian John
    I can't find an explanation either.
    But this one works for some reason:
    <script type="text/javascript">
    <!--
    if (screen.width <= 699) {
    document.location = "http://m.site.com";
    }
    //-->
    </script>

    I just tried it and it redirects very well.
    Signature
    ARE YOU A CONSULTANT? Do you have clients who could use MORE LEADS?
    Get them a MOBILE WEBSITE PLATFORM built to stay up with their clients habits.
    More than 50% of their customers buys from their mobile devices now!

    CLICK HERE FOR MORE INFO
    {{ DiscussionBoard.errors[3836025].message }}
  • Profile picture of the author ryank
    Where to put this code? I think I need it for my business.
    {{ DiscussionBoard.errors[3960300].message }}
    • Profile picture of the author Adrian John
      Originally Posted by ryank View Post

      Where to put this code? I think I need it for my business.
      Just place it in the index file of your website(in the source).
      In the<head> section. Anywhere after the <title> tag should be fine.
      That's how i use it.
      Signature
      ARE YOU A CONSULTANT? Do you have clients who could use MORE LEADS?
      Get them a MOBILE WEBSITE PLATFORM built to stay up with their clients habits.
      More than 50% of their customers buys from their mobile devices now!

      CLICK HERE FOR MORE INFO
      {{ DiscussionBoard.errors[3961719].message }}
      • Profile picture of the author cashtech29
        I tried it on one of my sites and it does redirect but
        the page is extremely small and I have to magnify.

        Should I be doing something else with the redirect mobile, other then just replacing the
        location to my mobile site dot com?
        {{ DiscussionBoard.errors[4098115].message }}
        • Profile picture of the author Jonas B
          Originally Posted by cashtech29 View Post

          I tried it on one of my sites and it does redirect but
          the page is extremely small and I have to magnify.

          Should I be doing something else with the redirect mobile, other then just replacing the
          location to my mobile site dot com?
          i think it is normal that your page is very small... because it is meant to be viewed on mobile phones and not in your browser
          Signature
          Proud owner of the most flexible mobile app builder. Check it out at http://bit.ly/hybrica!
          Mobile Web Expert & Android Developer
          {{ DiscussionBoard.errors[4098198].message }}
          • Profile picture of the author cashtech29
            [DELETED]
            {{ DiscussionBoard.errors[4098563].message }}
            • Profile picture of the author Adrian John
              Shoot me an email/pm when you get the chance.
              I'll try to help you fix your site.

              Adrian

              Originally Posted by cashtech29 View Post

              It seems to be my mobile site that is acting up and showing up small sometimes and
              at the right mobile size, on other occasions.

              Looks like I need to fixxxxx...
              Signature
              ARE YOU A CONSULTANT? Do you have clients who could use MORE LEADS?
              Get them a MOBILE WEBSITE PLATFORM built to stay up with their clients habits.
              More than 50% of their customers buys from their mobile devices now!

              CLICK HERE FOR MORE INFO
              {{ DiscussionBoard.errors[4101944].message }}
  • Profile picture of the author seabro
    Javascript is processed on the client side (ie. by the browser) not server side so if it works sometimes and not others, assuming the code has been correctly embedded in the html doc, either the browser doesnt support javascript or javascript is not enabled.

    The hosting/server doesnt make any difference where javascript is concerned.

    If you were using PHP/ASP to redirect that would be a different matter as this is handled on the server side.

    hope this helps
    {{ DiscussionBoard.errors[4102479].message }}
    • Profile picture of the author WillR
      Originally Posted by seabro View Post

      Javascript is processed on the client side (ie. by the browser) not server side so if it works sometimes and not others, assuming the code has been correctly embedded in the html doc, either the browser doesnt support javascript or javascript is not enabled.

      The hosting/server doesnt make any difference where javascript is concerned.

      If you were using PHP/ASP to redirect that would be a different matter as this is handled on the server side.

      hope this helps
      This exactly. The only reason a script like this would not work is because it has not been entered correctly OR the device or browser does not have javascript enabled.

      With a script like this you should also have something that displays for those users who do NOT have javascript enabled. This can be done using the noscript tags.
      {{ DiscussionBoard.errors[4319750].message }}
      • Profile picture of the author PrivateCitizen
        Originally Posted by WillR View Post

        This exactly. The only reason a script like this would not work is because it has not been entered correctly OR the device or browser does not have javascript enabled.

        With a script like this you should also have something that displays for those users who do NOT have javascript enabled. This can be done using the noscript tags.
        Care to elaborate about the noscript tags?
        {{ DiscussionBoard.errors[4319835].message }}
  • Profile picture of the author ganesh
    If you are interested in a PHP script, here is one: Toronto Computer Repair and Business IT Support Services Provider - PC Mechanix
    Signature

    {{ DiscussionBoard.errors[4104933].message }}

Trending Topics