Getting the current script executing filename in javascript

include, javascript, jquery, php

Solution

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

Problem

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['SCRIPT_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?

Original source