Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    Colorado
    Posts
    132
    Thanks
    7
    Thanked 1 Time in 1 Post

    indexOf() not working

    Code:
    <script language="JavaScript">
    if(window.location.indexOf('http://google.com') == -1) {
    window.location = 'http://google.com';
    }
    </script>
    The purpose of the script is to see if the user is at google.com, if not they are redirect them to google.com, otherwise not. Its not working and I have no idea why. Help please.
    -bubbles

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    You missed highlighted:
    Code:
    if(window.location.href.indexOf('http://google.com') == -1)
    Without the one in red, your script will still work.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Location
    Colorado
    Posts
    132
    Thanks
    7
    Thanked 1 Time in 1 Post
    thanks
    Last edited by bubbles19518; 07-30-2008 at 04:51 AM.
    -bubbles


  •  

    Posting Permissions

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