Skip to content Skip to sidebar Skip to footer

Url Fragments And The Base Tag

I'm using the tag in an application to simplify development. I'm aware of the 'feature' that occurs when an anchor is only a URL fragment, as in it routes to the

Solution 1:

Ok, so, I think I understand the question now.

This has been tested in Google Chrome and Firefox.

Add this javascript at the end of the body:

base=document.getElementsByTagName("base"); 
base=base[0].href;

links=document.getElementsByTagName('a');

for(index in links){
    if(links[index].href.indexOf(base+"#")==0){
        links[index].href=document.location+links[index].href.slice(links[index].href.indexOf("#"));
    }
}

Solution 2:

Don't use relative urls. The base tag won't affect urls like /home or http://google.com, but it will effect about/us or users/12

Post a Comment for "Url Fragments And The Base Tag"