View Full Version : Retrieving name of file that calls script

05-08-2006, 05:56 AM
Sorry to ask another newbie question. I can do this so easily in PHP but I am a complete beginner with javascript.

My files teacher_bob.html, teacher_joe.html, teacher_etc.html all call the same javascript.

Within that javascipt I want to get the name of the calling file.

So if the script was called from teacher_bob.html I want the "teacher_bob" part read into a variable for later use.

In PHP I could do something like this:

$teacherName = "./images/" . basename($HTTP_SERVER_VARS["SCRIPT_NAME"], ".html");

I cannot find an equivelant for javascript. Any help would be greatly appreciated.

05-08-2006, 12:41 PM
Any help would be greatly appreciated.
Use location.pathname:

<script type="text/javascript">