Re: javascript filename
- From: huchengtw@xxxxxxxxx
- Date: 10 Aug 2005 01:25:48 -0700
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
.
- References:
- javascript filename
- From: mgershma@xxxxxxxxxxx
- Re: javascript filename
- From: RobG
- javascript filename
- Prev by Date: Re: javascript filename
- Next by Date: Re: Firefox not loading dom quickly enough: how to wait?
- Previous by thread: Re: javascript filename
- Next by thread: Re: javascript filename
- Index(es):
Relevant Pages
|