开发者

Getting the current script executing filename in javascript

Okay, I've been searching for this for way too long already... I'm trying to find out how I can return the filename of the page that's running an included javascript, from inside that javascript.

I can easily do this in PHP using $_SERVER['SC开发者_运维问答RIPT_FILENAME'], but in Javascript this seems to be a lot harder.

Do I really need to substring it from location.href or is there a more efficient way? Could jQuery help?


Remove the Url Parameters

function getFileName()
{
  var url = window.location.pathname;
  var lastUri = url.substring(url.lastIndexOf('/')+1);
  if(lastUri.indexOf('?')!= -1)
     return lastUri.substring(0,lastUri.indexOf('?'));
  else
     return lastUri;
}


var url=location.href;
return url.substring(url.lastIndexOf('/')+1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜