Results 1 to 3 of 3

Thread: window.location without # but with anchor name?

  1. #1
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default window.location without # but with anchor name?

    Hi,

    I'm using the following code

    Code:
    var myPage = window.location;
    to get the URL of the page and have it replacing
    Code:
    ' + myPage + '
    in a document.write.

    If I have an anchor on a page

    http://mydomain.com/folder/pagename.html#2

    I would like the window.location to return

    http://mydomain.com/folder/pagename.html2

    hence without # but with the anchor name.

    Is there any way I can have it eliminating the #? (Something like replace # with nothing, take it out or such?)

    Thanks for any help you can provide...
    Last edited by jscheuer1; 01-07-2011 at 06:42 AM. Reason: kill bogus hotlinks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Using window.location will always return a # if there is a hash in the URL.

    Yes you can strip it, but you need to make sure it's a string first:

    Code:
    var myPage = (window.location.href).replace(/#/, '');
    The href is always a string.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much John! that worked like a charm!

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
  •