window.location.href - drop part of url if it is like page#id

Discussion in 'JavaScript' started by tautvys92, Jun 2, 2010.

  1. #1
    I need to transform url from /page#id to /page when refreshing the page.

    I'm using window.location.href = window.location.href to refresh. Any solutions? should I combine if with other function?
     
    tautvys92, Jun 2, 2010 IP
  2. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use slice like:

    
    //your url
    my_url = 'http://www.my_site.com/page#9';
    //the last index of the # sign
    b = my_url.lastIndexOf('#');
    //slicing from 0 (begining of string) to b (the # sign)
    new_url = my_url.slice(0,b);
    //output should be http://www.my_site.com/page
    
    Code (markup):
    Cheers!
     
    Imozeb, Jun 2, 2010 IP
  3. tautvys92

    tautvys92 Peon

    Messages:
    246
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you. Thats exactly what I needed.
     
    tautvys92, Jun 2, 2010 IP
  4. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No problem. :)
     
    Imozeb, Jun 3, 2010 IP