Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Filename

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
US
I'm looking for a way to get the current filename from an included js file (not the js file the page's file).

Here is what I have so far.

index.html
Code:
    <script src="jsFile.js" type="text/javascript"></script>
</head>

jsFile.js
Code:
//var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
var sPath = window.fileName;//window.location.host;
//var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
alert(sPath);

As you can see I've tried pulling the location from several different locations (including several "document" properties).

There is a problem with many of the methods that I found. All the methods are based on the URL of the page - the URL you see in the address bar. This can cause a problem if the page is index.html which is accessible from or
I need to have the javascript return the current filename regardless of what the visible URL is (or invisible in the case of frames). Note: index.html is just an example - it could very easily be index.php, default.html, default.php, index.aspx, etc... - anything that would be a default page.

Any ideas on how to do this?
 
Yes, but it does not fit the requirements (I have tried that one too).

If you use that with your page being " you would not get a filename. You would only get a filename if you specified " That is where the difficulty lies - in getting the filename for those default pages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top