Mat*_*att 5 javascript location referrer pathname
如何在javascript中使用document.location.pathname中的相同功能 - 除了引用者?像document.referrer.pathname这样的东西?
谢谢.
不,您只能手动提取所需的部分:
document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '')
Run Code Online (Sandbox Code Playgroud)
您可以从 中提取路径名document.referrer并new URL()使用以下代码对其进行解析
const url = new URL(document.referrer)
url.pathname
Run Code Online (Sandbox Code Playgroud)
确保为 IE 10 及以下版本填充 URL,使用https://polyfill.io/v3/polyfill.js?features=URL轻松完成
| 归档时间: |
|
| 查看次数: |
3741 次 |
| 最近记录: |