Getting current script executable file name in javascript

Ok, I have been looking for this for too long ... I am trying to figure out how I can return the file name on a page that runs javascript included, from within this javascript.

I can easily do this in PHP with $_SERVER['SCRIPT_FILENAME'], but in Javascript it looks a lot more complicated.

Do I need to tune it out location.hrefor is there a more efficient way? Can jQuery help?

+3
source share
2 answers

Removing 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;
}
+3
source
var url=location.href;
return url.substring(url.lastIndexOf('/')+1)
+2
source

Source: https://habr.com/ru/post/1731301/


All Articles