Redirection script mobile site

by 10 replies
14
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
#offline marketing #mobile #redirection #script #site
  • 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.
  • Where to put this code? I think I need it for my business.
    • [1] reply
    • 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.
      • [1] reply
  • 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
    • [1] reply
    • 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.
      • [1] reply
  • If you are interested in a PHP script, here is one: Toronto Computer Repair and Business IT Support Services Provider - PC Mechanix
    • [ 1 ] Thanks

Next Topics on Trending Feed