js 地址栏路径
//获取当前窗口的Url
var url = window.location.href;
//结果:http://localhost:8080/homePage/Index?id=0&type=1
//获取当前窗口的主机名
var host = window.location.host;
//结果:localhost:8080
//获取当前窗口的端口
var port = window.location.port;
//结果:8080
//获取当前窗口的路径
var pathname = window.location.pathname;
//结果:/homePage/Index
//获取当前文档的Url
var URL = document.URL;
//结果:http://localhost:8080/homePage/Index?id=1&type=1
//获取参数
var search = window.location.search;
//结果:?id=1&type=1
获取路径或者url的最后一段
var pathname = window.location.pathname;
function getLastItem(url){
return url.substring(url.lastIndexOf('/') + 1);
}
调用: getLastItem(pathname)
结果:Index

浙公网安备 33010602011771号