JavaScript/url
来自康健生活
引言
location
| hash | 从 # 开始的 URL
|
| host | 主机名 + 端口号 |
| hostname | 当前 URL 的主机名 |
| href | 完整的 URL |
| pathname | 当前 URL 的路径部分 |
| port | 当前 URL 的端口 |
| protocol | 当前 URL 的协议 |
| serach | 从 ? 开始的 URL
|
正则
function getQueryString(name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
};
return null;
}
No categories