varjsrequest={//This is a static class with 2 static methods inside the class.//method One: Get the URL's file name such as Index.htmlGeturlname:function(URL) {//If the URL passed in is http://www.qq.com/index.html?name=joey here there are altogether 3 slashes, if we want to get index.htmlUrl=url.split ('? ') [0];//We just need the number .varUrlslashcount=url.split ('/'). Length;//statistics have 3 slashesreturnUrl.split ('/') [Urlslashcount-1].tolowercase ();//gets the last array of arrays},//method Two: Get the parameters inside the URL we pass a geturlparam ("CID", Window.location.search) can get the value of CID//Note that if the address of a Web page is Index.html?cid=joeylee, then his window.location.search is from the "No." Cid=joeylee This stringGeturlparam:function(name,url) {if(!URL) {URL=Window.location.search;}varSearurl=NewString (URL); Console.log (Searurl);varReg =NewRegExp ("(^|&)" + name + "= ([^&]*) (&|$)");//constructs a regular expression object that contains a target parametervarR =searurl.substr (1). Match (REG);//Match target Parametersif(r!=NULL)returnUnescape (r[2]);return NULL;//Return parameter Values} }
If htpp://localhost/index.php get index.php
var url = jsrequest.geturlname (window.location.href);
JS Gets the Address bar last file name