截取URL的最终页面名

来源:互联网 发布:考研英语二经验知乎 编辑:程序博客网 时间:2024/05/20 16:09

function getUrlFinalName(){

  var   docUrl   =   document.URL;  
  var   lastPipe   =   docUrl.lastIndexOf('/');  
  var   lastPeriod   =   docUrl.lastIndexOf('.');  
  var   fileName;  
   
  if   (lastPipe   <   lastPeriod)  
  fileName   =   docUrl.substring(lastPipe   +   1,   lastPeriod);  
  else  
  fileName   =   '';

  return fileName;

}

 

 

function getURLFinalName2(){

  var   url   =   "http://community.csdn.net/Expert/PostNew.asp"  
  //var   url   =   window.location.href  
  fileName   =   url.split("//")[1].split("/")  
  file   =   fileName[fileName.length-1].split(".")[0]  
  return file;

}

原创粉丝点击