SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript to get page url and split

    Is it possible to use JavaScript to get the page url in the address bar? Like this
    http://website.com/red/apple/page.html

    I would like to break something like this up into an array:
    [0] website.com
    [1] red
    [2] apple
    [3] page.html

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    location array

    You could use the location property and split() to get an array.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.javascriptkit.com/jsref/location.shtml
    http://www.javascriptkit.com/jsref/string.shtml

    Check out those 2 links, it should lead you in the right direction.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The location object has a number of properties the provide all you might want

    For the following URL, here is how to access each part
    http://www.oreilly.com:1234/catalog/...t&m=10#results

    location.protocol = 'http'
    location.host = 'www.oreilly.com:1234'
    location.hostname = 'www.oreilly.com'
    location.port = '1234'
    location.href = 'http://www.oreilly.com:1234/catalog/search.html?q=JavaScript&m=10#results'
    location.pathname = '/catalog/search.html'
    location.search = '?q=JavaScript&m=10'
    location.hash = '#results'
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very good Paul -- By the way thanks for that other 1x1 image processing script you created. I haven't had a chance to thank you! You are a wonderful human.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    You're very welcome. I was going to say "It's a pleasure..." and other guff, but that would be too snobbish. So instead of that I'll say, I'm glad I could help.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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