js获取url,截取url参数,截取url后⽂件名获取当前:
var url = window.location.href;
百度为例:
var url=window.location.href;
console.info(url);
www.jspp/testbin/apptest/app-site/explore.html;
split() ⽅法⽤于把⼀个字符串分割成字符串数组。
先⽤split('?')把URL和参数分离:
var url=window.location.href;
var urlArr = url.split('?');
  console.info(urlArr);
["www.jspp/testbin/apptest/app-site/explore.html"]
var url=window.location.href;var urlArr = url.split('?');
var k = urlArr[0], appU = k.split('/');
console.log(k);
console.log(appU);
得到:
VM363:1 www.jspp/testbin/apptest/app-site/explore.html
["http:", "", "www.jspp", "testbin", "apptest", "app-site", "explore.html"]
0:”http:"
字符串截取方法js1:""
2:"www.jspp"
3:"testbin"
4:"apptest"
5:"app-site"
6:"explore.html"
length:7
直接那数组最后⼀个就是⽂件名:
var L = appU[appU.length - 1];
console.log(L);//拿到当前页名称判断传递参数
得到:"explore.html"

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。