When it comes to path-related issues, everyone will think of window.location. Indeed, this object provides quite a lot of path information, among which the commonly used ones include:
1.location.href: The complete URL of the current page
2.location.pathname: The path name in the current URL
3.location.hash: Anchor point
in the current URL
4.location.search: query parameters in the current URL
However, location does not have an attribute that can directly obtain the absolute path of the current directory (excluding the file name). Through Google, I found some wrong methods, such as separating the URL into an array through "/", removing the last item of the array and then concatenating it into a string. But if the file name is not specified in the URL, the result is completely wrong.
Based on past coding experience, the href attribute of the a element will always return an absolute path, which means it has the ability to convert relative paths into absolute paths. I tried it using the following code, and it worked: