473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

access code of external scripts

Hi,

I'm trying to access the JavaScript code contained in a <scripttag
via its "text" attribute. This works well, if the code is embedded in
the HTML page. However, when the code is in an external file with the
"src" attribute, it does not work anymore.

Does anybody have an idea if there is any way (be it clean and simple
or as a workaround) to access the code of external scripts as well? I
read, that if there is something like

<script type="text/javascript" src="./myScript.js">
alert('hello world');
</script>

the external script and the embedded script are concatenate. So I
assume that the result of this concatenation has to be accessible
somehow.

Any ideas?

Thanks,

Stefan

Jun 7 '07 #1
10 2355
Stefan Weber wrote:
Hi,

I'm trying to access the JavaScript code contained in a <scripttag
via its "text" attribute. This works well, if the code is embedded in
the HTML page. However, when the code is in an external file with the
"src" attribute, it does not work anymore.
Why?
Does anybody have an idea if there is any way (be it clean and simple
or as a workaround) to access the code of external scripts as well? I
read, that if there is something like
I am not even entirely sure I know what you are after.
<script type="text/javascript" src="./myScript.js">
alert('hello world');
</script>
Since when does this work? That will not concatenate the external into
the internal. In fact, an internal declaration that matches the
external will not even overwrite the external.
the external script and the embedded script are concatenate. So I
assume that the result of this concatenation has to be accessible
somehow.
Share the URL with the rest of us so that it can forever be burned in
our minds as misinformation.

I would really like to know why you are going this route or what you are
after. You say you want to "access" the code found within a script tag
and that just sounds weird to me. If you want to access it, access it.

<script>
function accessed() { return 'Access Granted'; }
alert(accessed());
</script>

Just for kicks, you could read the contents of SCRIPT *or* use
XMLHttpRequest to read the script's contents.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 7 '07 #2
rf

"Stefan Weber" <st**********@gmail.comwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
Hi,
G'day.
<script type="text/javascript" src="./myScript.js">
alert('hello world');
</script>

the external script and the embedded script are concatenate. So I
assume that the result of this concatenation has to be accessible
somehow.

Any ideas?
Yes.

A quick investigation of the HTML specifications

http://www.w3.org/TR/html401/interac...ml#edef-SCRIPT

reveals:

<quote>
The script may be defined within the contents of the SCRIPT element or in an
external file. If the src attribute is not set, user agents must interpret
the contents of the element as the script. If the src has a URI value, user
agents must ignore the element's contents and retrieve the script via the
URI.
</quote>

Pretty clear. src or element content. Not both.

--
Richard.
Jun 7 '07 #3
I'm trying to access the JavaScript code contained in a <scripttag
via its "text" attribute. This works well, if the code is embedded in
the HTML page. However, when the code is in an external file with the
"src" attribute, it does not work anymore.

Why?
Because document.getElementsByTagName("script")[0].text returns the
empty string.
Does anybody have an idea if there is any way (be it clean and simple
or as a workaround) to access the code of external scripts as well? I
read, that if there is something like

I am not even entirely sure I know what you are after.
I would like to read the contents of the external file as a string
(i.e. it should have the same effect as doing

document.getElementsByTagName("script")[0].text

for an embedded script.
>
<script type="text/javascript" src="./myScript.js">
alert('hello world');
</script>

Since when does this work? That will not concatenate the external into
the internal. In fact, an internal declaration that matches the
external will not even overwrite the external.
I will post the URL if I can find it again.
>
I would really like to know why you are going this route or what you are
after. You say you want to "access" the code found within a script tag
and that just sounds weird to me. If you want to access it, access it.
I mean "access" in the sense of reading the script as string. Hmm, I
actually want to access a script element that does not contain
JavaScript. It contains an experimental scripting language that would
be interpreted by JavaScript, thus I need to access the string with
the source code.

I know this sounds weird, but it is just a very tiny step at the
beginning of something (hopefully) big :)
Just for kicks, you could read the contents of SCRIPT
I don't understand that? Do you mean using the "text" attribute of the
script element? This unfortunately does not work...
*or* use
XMLHttpRequest to read the script's contents.
I know, this would work. The problem with this is that this would send
an additional HTTP Request to the server. If possible, I want to avoid
that.

By the way, this only has to work in IE -- just in case ther is a
proprietary solution to the problem.

Thanks,

Stefan

Jun 7 '07 #4
A quick investigation of the HTML specifications

http://www.w3.org/TR/html401/interac...ml#edef-SCRIPT

reveals:

<quote>
The script may be defined within the contents of the SCRIPT element or in an
external file. If the src attribute is not set, user agents must interpret
the contents of the element as the script. If the src has a URI value, user
agents must ignore the element's contents and retrieve the script via the
URI.
</quote>

Pretty clear. src or element content. Not both.
Thank you :) But this is not the actual problem. I only want to access
the source code (as a string) from the external file.

Jun 7 '07 #5
Stefan Weber wrote:
>>I'm trying to access the JavaScript code contained in a <scripttag
via its "text" attribute. This works well, if the code is embedded in
the HTML page. However, when the code is in an external file with the
"src" attribute, it does not work anymore.
Why?

Because document.getElementsByTagName("script")[0].text returns the
empty string.
Ah, so. Well too bad you said it only has to work for Internet
Explorer. Opera, like the obsequious lapdog it is, lovingly offers you
the contents of an external script with that line of code.

Of course, any real browser behaves as expected. Surprisingly so does
Internet Explorer.
>>Does anybody have an idea if there is any way (be it clean and simple
or as a workaround) to access the code of external scripts as well? I
read, that if there is something like
I am not even entirely sure I know what you are after.

I would like to read the contents of the external file as a string
(i.e. it should have the same effect as doing

document.getElementsByTagName("script")[0].text
See above about Opera.
for an embedded script.
>><script type="text/javascript" src="./myScript.js">
alert('hello world');
</script>
Since when does this work? That will not concatenate the external into
the internal. In fact, an internal declaration that matches the
external will not even overwrite the external.

I will post the URL if I can find it again.
Please do. I will bookmark it as a source of misinformation. ;)
>I would really like to know why you are going this route or what you are
after. You say you want to "access" the code found within a script tag
and that just sounds weird to me. If you want to access it, access it.

I mean "access" in the sense of reading the script as string. Hmm, I
actually want to access a script element that does not contain
JavaScript. It contains an experimental scripting language that would
be interpreted by JavaScript, thus I need to access the string with
the source code.

I know this sounds weird, but it is just a very tiny step at the
beginning of something (hopefully) big :)
Gotcha.
>Just for kicks, you could read the contents of SCRIPT

I don't understand that? Do you mean using the "text" attribute of the
script element? This unfortunately does not work...
I meant exactly what you already knew.

document.getElementsByTagName('script')[0].text and .innerHTML
>*or* use
XMLHttpRequest to read the script's contents.

I know, this would work. The problem with this is that this would send
an additional HTTP Request to the server. If possible, I want to avoid
that.
Why? (I am just being nosy now.)

Anyway, you wish to eliminate an additional HTTP request? Then don't
even load the script. Use an XHR to grab it and process it as you see fit.
By the way, this only has to work in IE -- just in case ther is a
proprietary solution to the problem.
Is this for an intranet application? If not, shame on you.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 7 '07 #6
Stefan Weber wrote:
But this is not the actual problem. I only want to access
the source code (as a string) from the external file.
You can try to read it, for instance using XMLHTTP and its responseText
property.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 7 '07 #7
*or* use
XMLHttpRequest to read the script's contents.
I know, this would work. The problem with this is that this would send
an additional HTTP Request to the server. If possible, I want to avoid
that.

Why? (I am just being nosy now.)
Because "my" scripting language should be processed as naturally as
possible, i.e. if possible in the same way as JavaScript.
Anyway, you wish to eliminate an additional HTTP request? Then don't
even load the script. Use an XHR to grab it and process it as you see fit.
Hmm, don't get you here. The browser automatically does the request
anyway. So the XHR would be the second request for the same source
anyway (at least this would probably use the cached version). How do
you suggest to do it with only a single request per script?
By the way, this only has to work in IE -- just in case ther is a
proprietary solution to the problem.

Is this for an intranet application? If not, shame on you.
I'd call it a research prototype. I know it's not nice, but if we get
this working somehow, I see a chance that browsers will support this
kind of scripting language in the future more naturally.

Jun 8 '07 #8
On 7 Jun., 17:43, Martin Honnen <mahotr...@yahoo.dewrote:
Stefan Weber wrote:
But this is not the actual problem. I only want to access
the source code (as a string) from the external file.

You can try to read it, for instance using XMLHTTP and its responseText
property.
Thanks, I'll do it like that if I can't find another possibility. As
mentioned in another post, this would obviously result in having two
HTTP requests for every external script--I would like to avoid.

Jun 8 '07 #9
Stefan Weber wrote:
Thanks, I'll do it like that if I can't find another possibility. As
mentioned in another post, this would obviously result in having two
HTTP requests for every external script--I would like to avoid.
In many cases you can expect the browser to fetch the script file from
its cache on the second request.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 8 '07 #10
Stefan Weber wrote:
>>>*or* use
XMLHttpRequest to read the script's contents.
I know, this would work. The problem with this is that this would send
an additional HTTP Request to the server. If possible, I want to avoid
that.
Why? (I am just being nosy now.)

Because "my" scripting language should be processed as naturally as
possible, i.e. if possible in the same way as JavaScript.
>Anyway, you wish to eliminate an additional HTTP request? Then don't
even load the script. Use an XHR to grab it and process it as you see fit.

Hmm, don't get you here. The browser automatically does the request
anyway. So the XHR would be the second request for the same source
anyway (at least this would probably use the cached version). How do
you suggest to do it with only a single request per script?
Like Mr. Honnen said in another post. But more specifically I meant,
don't load your script via a SCRIPT tag.

Use an XHR to do it, then parse it when you get it. Thereby, only one
request.
>>By the way, this only has to work in IE -- just in case ther is a
proprietary solution to the problem.
Is this for an intranet application? If not, shame on you.

I'd call it a research prototype. I know it's not nice, but if we get
this working somehow, I see a chance that browsers will support this
kind of scripting language in the future more naturally.
I am not sure I follow. You plan on reinventing JavaScript?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 10 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Anderson | last post by:
Problem in short: user is moving (clicking a link) from my page before some JS code is run (to write a cookie). The code does not run (in Body's onLoad event) until the page loads as there are a...
18
by: Arthur Connor | last post by:
Is there a way of extracting the Javascript code from the "normal" HTML code (e.g. similar to CSS code which can be put into a separate file) ? If you offer a solution: can I determine in your...
10
by: Pasquale | last post by:
hello wverybody... i've got a terrible matter with JS my browsers (either IE and NN) load the external scripts uncorrectly...they load the files from the half part of them and not from the...
3
by: Bill Willyerd | last post by:
Hello All, I have been searching for a published document for Best Practices concerning access levels based on roles. Should developers have more than (if at all) select level access to...
6
by: Mellow Crow | last post by:
Just discovered this technique. Is this old hat? Would there be any disadvantage to doing this? In your external .js file: /* Summary: includes external scripts in this external script so...
17
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script...
7
by: clintonG | last post by:
To all Microsoft partners and customers who have been unable to download recently or access ASP.NET documentation from the msdn2 website and for all of those customers who have been lied to and...
1
by: ladybanks | last post by:
I am trying to load data from two separate tables into a third table. Log the load time into another table. However anytime i run my scripts in Access, the data doesnt load and i get variable exist...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.