js获取当前页面的URL

来源:互联网 发布:网络直播需要哪些设备 编辑:程序博客网 时间:2024/05/01 11:46

当前页面路径Url=http://localhost:8080/shopping/buyCart.shtml?skuId=510&amount=1

//获取当前窗口的Url
window.location.href

//获取当前窗口的主机名 例如:http://localhost:8080
window.location.host

//获取当前窗口的端口 例如: 8080
window.location.port

//获取当前窗口的路径 例如: /shopping/buyCart.shtml
window.location.pathname

//获取当前文档的Url
document.URL

//获取参数 例如: ?skuId=510&amount=1
window.location.search

//跳出当前窗口,打开新窗口
window.open(url);

从当前页(带上当前访问路径)跳转到登陆页面
//跳转到登陆页面
function login(){
window.location.href = “/shopping/login.shtml?returnUrl=” + window.location.href;
}

原创粉丝点击