如何在javascript中使用document.location.pathname中的相同功能 - 除了引用者?像document.referrer.pathname这样的东西?
谢谢。
不,您只能手动提取所需的部分:
document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '')
您可以使用document.referrer
获取引用文档的URL。你是这个意思吗??
您可以从document.referrer
中提取路径名,并使用以下代码使用new URL()
进行解析
const url = new URL(document.referrer)
url.pathname
请务必使用https://polyfill.io/v3/polyfill.js?features=URL轻松完成IE 10及更低版本的填充URL