What are the recommendations for html <base> tag?

前端 未结 17 2230
一向
一向 2020-11-21 10:17

I\'ve never seen HTML tag actually used anywhere before. Are there pitfalls to its use that means I should avoid it?

The fact that I have never noticed

相关标签:
17条回答
  • 2020-11-21 10:51

    I have found a way to use <base> and anchor based links. You can use JavaScript to keep links like #contact working as they have to. I used it in some parallax pages and it works for me.

    <base href="http://www.mywebsite.com/templates/"><!--[if lte IE 6]></base><![endif]-->
    
    ...content...
    
    <script>
    var link='',pathname = window.location.href;
    $('a').each(function(){
        link = $(this).attr('href');
        if(link[0]=="#"){
            $(this).attr('href', pathname + link);
        }
    });
    </script>
    

    You should use at the end of the page

    0 讨论(0)
  • 2020-11-21 10:51

    Base href example

    Say a typical page with links:

    <a href=home>home</a> <a href=faq>faq</a> <a href=etc>etc</a>
    

    .and links to a diff folder:

    ..<a href=../p2/home>Portal2home</a> <a href=../p2/faq>p2faq</a> <a href=../p2/etc>p2etc</a>..
    

    With base href, we can avoid repeating the base folder:

    <base href=../p2/>
    <a href=home>Portal2-Home</a> <a href=faq>P2FAQ</a> <a href=contact>P2Contact</a>
    

    So that's a win.. yet pages too-often contain urls to diff bases And the current web supports only one base href per page, so the win is quickly lost as bases that aint base∙hrefed repeats, eg:

    <a href=../p1/home>home</a> <a href=../p1/faq>faq</a> <a href=../p1/etc>etc</a>
    <!--.. <../p1/> basepath is repeated -->
    
    <base href=../p2>
    <a href=home>Portal2-Home</a> <a href=faq>P2FAQ</a> <a href=contact>P2Contact</a>
    


    Conclusion

    (Base target might be useful.) Base href is useless as:

    • page is equally WET since:
      • default base [–parent folder] ⇌ perfect (unless unnecessary/rare exceptions 𝒞1 & 𝒞2).
      • current web ⇌ multiple base hrefs unsupported.

    Related

    • comparison with Apache∙rewrite base
    0 讨论(0)
  • 2020-11-21 10:52

    The hash "#" currently works for jump links in conjunction with the base element, but only in the latest versions of Google Chrome and Firefox, NOT IE9.

    IE9 appears to cause the page to be reloaded, without jumping anywhere. If you are using jump links on the outside of an iframe, while directing the frame to load the jump links on a separate page within the frame, you will instead get a second copy of the jump link page loaded inside the frame.

    0 讨论(0)
  • 2020-11-21 10:53

    It makes pages easier for offline viewing; you can put the fully qualified URL in the base tag and then your remote resources will load properly.

    0 讨论(0)
  • 2020-11-21 10:53

    I've never really seen a point in using it. Provides very little advantage, and might even make things harder to use.

    Unless you happen to have hundreds or thousands of links, all to the same sub-directory. Then it might save you a few bytes of bandwidth.

    As an afterthought, I seem to recall there being some problem with the tag in IE6. You could place them anywhere in the body, redirecting different portions of the site to different locations. This was fixed in IE7, which broke a lot of sites.

    0 讨论(0)
提交回复
热议问题