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
jsFile.js
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?
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?