Re: all script functions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




Praveen wrote:
[snip]
But still Im not able to get the text of included .js files.
Here is the sample which I tried.
I want to get the contents of the included Test.js file.

<HTML>
<HEAD>
<script language = javascript src=Test.js></script>
</HEAD>
<script>
function F(){
//Im able to get this right
alert(document.scripts.item(1).text)
//this is coming as blank
alert(document.scripts.item(0).text)
}
</script>
[/snip]

I suspect this is because the browser does count the linked file as
"text" for the purposes of the text property. I.e. the text property
retrieves text between the script tags <script>// Text Here</script>.

Or perhaps "Test.js" does not exist in the same domain and folder as
your web page. I.e. "Test.js" is a relative URL, is it pointing to the
right place?

Why do you need to get the text of the script if it is your own script
in the first place?

Alternatives to consider are:-

(a) If it is a local file on your computer, use the ActiveXObject
"Scripting.FileSystemObject".

(b) If it is a remote file, use an HTTPRequest object, and get the
script as a String through the "responseText" property.

Regards

Julian Turner

.



Relevant Pages