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