Having Problems With Javascript Redirect

4 replies
Hi Everyone

I have created a mobile friendly site for myself and want to redirect visitors if they find it with a resolution of more than 600 pixels to my main site.

The script I'm using is this:

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

I have placed this code between the <head> and </head> tags but the screen if anything refreshes but does not redirect.

Hope you get the gist and can help

Thanks

Chris
#javascript #problems #redirect
  • Profile picture of the author pc101seo
    Some mobile phones are not compatible with java script, try it on some other mobile phones and see the effect.
    {{ DiscussionBoard.errors[3444180].message }}
    • Profile picture of the author Christopher Raine
      Hi pc101seo

      This issue is if some one found my mobile site via conducting a search from their desktop. If this occurs it should direct them to my main site. If some one finds my mobile site through their mobile the site is coded to be optimized for mobile viewing with all the top mobile variants on the market today!

      Chris
      Signature

      Get your affiliate marketing business off to a good start, visit Secret Affiliate Cash and pick up your Free Affiliate Marketing Report.

      {{ DiscussionBoard.errors[3444250].message }}
  • Profile picture of the author cfountain
    Chris

    The line break in the window.location redirect does cause a JS error. Be sure that the command is all on one line.

    if (width >=600) {window.location='http://mysite.com/'}

    If that does not fix your problem, it is possible that there is another Javascript error somewhere else on the page. It may not even be related to particular script.

    Open up your browser error console and look for errors. I recommend using Firefox for your Javascript code testing. To open the error console in FF use the following menu option: Tools->Error Console

    -Clint
    {{ DiscussionBoard.errors[3446948].message }}
    • Profile picture of the author Christopher Raine
      Originally Posted by cfountain View Post

      Chris

      The line break in the window.location redirect does cause a JS error. Be sure that the command is all on one line.

      if (width >=600) {window.location='http://mysite.com/'}

      If that does not fix your problem, it is possible that there is another Javascript error somewhere else on the page. It may not even be related to particular script.

      Open up your browser error console and look for errors. I recommend using Firefox for your Javascript code testing. To open the error console in FF use the following menu option: Tools->Error Console

      -Clint
      Hi Clint

      It works fantastic!!

      Many Thanks

      Chris
      Signature

      Get your affiliate marketing business off to a good start, visit Secret Affiliate Cash and pick up your Free Affiliate Marketing Report.

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

Trending Topics