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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I need help with simple Script

    Hello,
    I am taking a college course for javascript and I'm stuck on an assignment.

    I need to write an if/then statement that is declaired by the url in the address bar.

    If - url in address bar = www.princetonuniversity.com/index.html
    Then - display <html> home page </html>
    ELSE
    If - url in address bar = www.princetonuniversity.com/about.html
    Then - display <html> about us page </html>


    Can someone give me an example on how to write this script?

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by th4shmetal View Post
    Hello,
    I am taking a college course for javascript and I'm stuck on an assignment.

    I need to write an if/then statement that is declaired by the url in the address bar.

    If - url in address bar = www.princetonuniversity.com/index.html
    Then - display <html> home page </html>
    ELSE
    If - url in address bar = www.princetonuniversity.com/about.html
    Then - display <html> about us page </html>


    Can someone give me an example on how to write this script?
    This involves reading and if necessary writing to the window.location.href property.
    The only real complication here is that a direct comparison using == or != is inadequate, because the URL will contain other characters like 'http://'.
    The easiest solution for you will be to use the String.indexOf function.


  •  

    Posting Permissions

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