Why base tag does not work for relative paths?

前端 未结 2 702
[愿得一人]
[愿得一人] 2020-12-08 01:40

I have a tag as below in section of the page:


<         


        
相关标签:
2条回答
  • 2020-12-08 02:31

    Try having your base tag like:

    <base href="http://localhost/framework/">
    

    and your script tag like:

    <script src="assets/jquery-1.7.1.min.js">
    
    0 讨论(0)
  • 2020-12-08 02:42

    /assets/jquery-1.7.1.min.js is not relative but absolute*, the / takes it to the root even with a base tag.

    If you remove that /, it should make it relative off the current path, which, when a base tag is present would be http://localhost/framework/.

    Note: You will also need to add a trailing / to the end of the href, to indicate that it's a folder.

    Full working example:

    <!doctype html>
    <html>
    <head>
    <base href="/test/" />
    <script src="assets/test.js"></script>
    <body>
    hi
    </body>
    </html>
    

    * Actually depending on who you ask, it's still relative since it is relative off the current domain. But I prefer to call this absolute since it's signifying the path is from the root, based on the current domain. Although, I guess technically that makes it relative in the grand scheme of things, and absolute only in terms of the current domain. Whatever.

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