Skip to content Skip to sidebar Skip to footer

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 t

Solution 1:

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;
}

Solution 2:

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

Post a Comment for "Getting The Current Script Executing Filename In Javascript"