473,507 Members | 6,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why isnīt this possible?

Iīm trying to make an application with if ...something
else if ... something else to dinamically change a src script,
can't this be done ? and if so why not ?
Thanks in advance , Oscar Monteiro
<span id="script">
<script type="text/javascript" >
script.innerHTML="script src='a.js' ";
</script>

Jul 23 '05 #1
9 2540
Oscar Monteiro wrote:
Iīm trying to make an application with if ...something
else if ... something else to dinamically change a src script,
can't this be done ? and if so why not ?
JavaScript defined in a script block is executed as and when the HTML
page is initially interpreted. This includes reading in any functions
defined in the script block. If you try programmatically changing the
content of a script block, I don't think the behaviour is defined.

However, a possibility is to do something like

<script type="text/javascript"><!--

document.write('<script type="text/javascript" src="a.js"><\/script>');

// --></script>

Note the backslash, which makes extra sure that the closing script tag
that you write out isn't interpreted as the end of this code.

The exact time at which the included script is processed in relation to
the script that includes it isn't well defined. You'll need to end this
script block and start another before you can use functions defined in
the .js file.
<span id="script">
<script type="text/javascript" >
script.innerHTML="script src='a.js' ";
</script>


If this worked, you would end up with

<span id="script">script src='a.js' </span>

which obviously isn't what you intended. Before you count the fact that
you have nothing with a _name_ (as opposed to id) of script.

Stewart.
Jul 23 '05 #2
VK
IMHO the question was:

Why JavaScript (at least in its ISO-blessed ECMA version) still refuses to
add standard precompiler instructions like
#if
#elseif
#const
etc.

The sincere answer would be: "God knows: why!".
Maybe they just like to see us being stoke in "90's forever" with these ugly
....
else (document.write("<scr"+"ipt src='some.js'>"+"</scr"+"ipt>");)
....
Jul 23 '05 #3
On Thu, 21 Oct 2004 17:00:05 +0100, Stewart Gordon <sm*******@yahoo.com>
wrote:

[snip]
<span id="script">
<script type="text/javascript" >
script.innerHTML="script src='a.js' ";

[snip]
Before you count the fact that you have nothing with a _name_ (as
opposed to id) of script.


Even so, an identifier matching the name of an element does not, by
itself, access that element. The appropriate collection, whether it be
document.forms, .links, .images, should also be used.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
On Thu, 21 Oct 2004 19:13:26 +0200, VK <sc**********@yahoo.com> wrote:

[snip]
Why JavaScript (at least in its ISO-blessed ECMA version) still refuses
to add standard precompiler instructions like
#if
#elseif
#const
etc.

The sincere answer would be: "God knows: why!".
ECMAScript makes no assumptions as to the environment in which it runs.
Such extensions would be just that: extensions. Besides, you can simulate
conditional compilation with standard language constructs, which is
probably why it isn't an extension to an existing implementation.

By the way, you never know what might be added in future as ECMAScript has
a large list of reserved keywords (most from Java):

abstract enum int short
boolean export interface static
byte extends long super
char final native synchronized
class float package throws
const goto private transient
debugger implements protected volatile
double import public

[snip]
else (document.write("<scr"+"ipt src='some.js'>"+"</scr"+"ipt>");)


At the very least, that last part should be changed to:

'<\/src' + 'ipt>'

Although there is no current evidence to suggest that browsers do
interpret a </ sequence to mean the end of a SCRIPT element, for the sake
of an extra character, you shouldn't take that risk.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
In article <41***********************@news.telepac.pt>, of**@hotmail.com
enlightened us with...
I=3Fm trying to make an application with if ...something
else if ... something else to dinamically change a src script,
can't this be done ? and if so why not ?
Thanks in advance , Oscar Monteiro
<span id="script">
<script type="text/javascript" >
script.innerHTML="script src='a.js' ";
</script>


See here for an example of dynamic script elements. DOM browsers only.
http://www.ipwebdesign.net/kaelisSpa...alidation.html

--
--
~kaeli~
Murphy's Law #2000: If enough data is collected, anything
may be proven by statistical methods.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #6
Oscar Monteiro wrote:
Iīm trying to make an application with if ...something
else if ... something else to dinamically change a src script,
can't this be done ? and if so why not ?


Yes, you can dynamically change the src attribute of a script tag. But
only in IE. In any other browser you have to create a new script tag and
load the src file. Do a search of the c.l.j archives for "dynamically
loading .js file" and you can find threads where, among other people, I
have talked about doing just what you want to do.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
VK
ECMAScript makes no assumptions as to the environment in which it runs.
But it should. It never pretended on the Java's WORA slogan, so this
pharossy is escaping my understanding.
Besides, you can simulate conditional compilation with standard language constructs,

Anything can be done in more than one way. Just look at NN4/IE4 - compatible
historic scripts: A monument to the human creativity non-surrender spirit.
But why to keep it this way?
By the way, you never know what might be added in future as ECMAScript >
Why it is not done now?
"God knows: why" - my answer remains the most profound one.
At the very least, that last part should be changed to:

'<\/src' + 'ipt>'


.... and so on: thank you for an illustration of how ugly the current
situation is with the pseudo-precompiled instructions.
Jul 23 '05 #8
On Fri, 22 Oct 2004 10:56:26 +0200, VK <sc**********@yahoo.com> wrote:
ECMAScript makes no assumptions as to the environment in which it runs.
But it should.


No, it shouldn't. It is a scripting language with applications outside of
browsers, so there cannot be any assumptions about the environment.
It never pretended on the Java's WORA slogan, so this pharossy is
escaping my understanding.


Pharossy?

[snip]
By the way, you never know what might be added in future as ECMAScript >


Why it is not done now?


Because there's no need. If the precondition can be evaluated on the
server, it can insert the required script. If not, a script replace
functions at runtime to adapt to its environment. That, in fact, provides
more functionality. Preprocessing instructions are executed at parse-time,
which may not be an appropriate moment to evaluate the environment, so
again, I fail to see the need.

[snip]
At the very least, that last part should be changed to:

'<\/src' + 'ipt>'


... and so on: thank you for an illustration of how ugly the current
situation is with the pseudo-precompiled instructions.


The correction had nothing to do with the "current situation", as you see
it. Escaping the backslash should be done with *every* closing tag, not
just closing SCRIPT tags. Perhaps you should read
<URL:http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.2>. Of course,
this only applies within a HTML document. If the script is in an external
file, there's no problem.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #9
VK wrote:
IMHO the question was:

Why JavaScript (at least in its ISO-blessed ECMA version) still refuses to
add standard precompiler instructions like
#if
#elseif
#const
etc.
Because JavaScript has no standard precompiler.

And because some consider the preprocessor to be an abomination. This
is part of the design of D:

http://www.digitalmars.com/d/overview.html
(scroll down to 'Features to Drop')

But then, I'm not sure what this is to do with anything....
The sincere answer would be: "God knows: why!".
Maybe they just like to see us being stoke in "90's forever" with these ugly
...
else (document.write("<scr"+"ipt src='some.js'>"+"</scr"+"ipt>");)
...


That doesn't look like valid JS syntax.

Stewart.
Jul 23 '05 #10

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

Similar topics

25
3319
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
14
14715
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
83
15517
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include...
9
9667
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.