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
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    location object question

    if location is a property of window object that returns a string and im appending .indexOf() to location why is it not working?

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    725
    Thanks
    35
    Thanked 132 Times in 123 Posts
    location (window.location) refers to an object- it has a toString method that returns the location's url.

    This happens for example, when you alert(location) or document.write(location).

    But location is an object with several properties and methods.

    To use string methods on the location.href, explicitly get a string from the location object.

    You can use var url= location.href or url=String(location).

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh ok that makes total sense. So I wasn't able to get any kind of string because the location object is just the address bar itself meaning that it can not return a string. But once i have access to the location object i can then use it's own properties like 'href' and that will give me the url as the returned string. Is that about right?


  •  

    Posting Permissions

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