Why base tag does not work for relative paths?

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

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


<         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    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:

    
    
    
    
    
    
    hi
    
    
    

    * 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.

提交回复
热议问题