Re: javascript filename



Dear,

Using oScript.src may be a great solution to solve it. But, in my
experience, HTML Document in IE will download it asynchronously. So, if
you set oScript.src and evaluate the variables or functions
immediately, you will get an undefined exception.

Because my js just runs in IE. So, I use an ActiveX Object (XMLHTTP
object) to download the source code. After I get the source code, I
append it to oScript.text. In this way, IE will load these source code
immediately, and you can use them right now.

ex:

var objHTTP = new ActiveXObject("Msxml2.XMLHTTP.4.0");
objHTTP.open("GET", filename, false);
objHTTP.send();
if(objHTTP.readyState == 4)
{
oScript.text=oScript.text + objHTTP.responseText;
}

var oObj=eval(function name);


RobG 寫道:

> mgershma@xxxxxxxxxxx wrote:
> > Hi.
> >
> > Does anybody know how can JavaScript get the filename of the file
> > it's
> > located in?
>
> You could try removing script elements with src attributes one at a time
> then call the function. If the call fails you could guess that the
> failure was because you removed that particular element. But it would
> not be very pretty or robust I expect.
>
> >
> > For example, file 'mike.js' contains several functions and
> > variables. I would like to set the variable to the filename of this
> > file dynamically:
> >
> > var sourceFileName = "mike.js";
> >
>
> You can create new script elements and give them a src attribute that
> contains the URI of a script file:
>
> var oScript = document.createElement('script');
> oScript.type = 'text/javascript';
> oScript.src = 'mike.js';
> document.body.appendChild( oScript );
>
>
> --
> Rob

.



Relevant Pages

  • .NET Mass Downloader Version 1.2 Released
    ... Welcome to the .NET Mass Downloader project. ... Batch download the Microsoft .NET Reference Source code. ... directory is the cache directory set in Visual Studio ...
    (microsoft.public.dotnet.languages.csharp)
  • .NET Mass Downloader Version 1.2 Released
    ... Welcome to the .NET Mass Downloader project. ... Batch download the Microsoft .NET Reference Source code. ... directory is the cache directory set in Visual Studio ...
    (microsoft.public.dotnet.languages.vb)
  • .NET Mass Downloader Version 1.2 Released
    ... Welcome to the .NET Mass Downloader project. ... Batch download the Microsoft .NET Reference Source code. ... directory is the cache directory set in Visual Studio ...
    (microsoft.public.dotnet.framework)
  • .NET Mass Downloader Version 1.2 Released
    ... Welcome to the .NET Mass Downloader project. ... Batch download the Microsoft .NET Reference Source code. ... directory is the cache directory set in Visual Studio ...
    (microsoft.public.dotnet.framework.windowsforms)
  • .Net Framework Source Code Downloader
    ... Welcome to the .NET Mass Downloader project. ... get it one file at a time while you're debugging. ... batch download it for reading or to populate the cache, ... Batch download the Microsoft .NET Reference Source code. ...
    (microsoft.public.dotnet.framework.windowsforms)