JS Gets the Address bar last file name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.