Question about function javascript

J

jaco

hello all
I have two js files

file1.js contain
var msg="Hello world";

------
file2.js
alert(msg);
-----------------

I want to know if posible
in my index.html page i have
only
<Script type="text/javascript" Language="JavaScript" Src="file2.js
"></script>


i want that file1.js included file2.js
i want the scope function of file1 ,"know" the scope of file2.js

with out contain this '<Script type="text/javascript"
Language="JavaScript" Src="file1.js "></script>'

in my index.html

Best Regards
jaco
 
S

SAM

Le 9/10/09 8:58 AM, jaco a écrit :
hello all
I have two js files

file1.js contain
var msg="Hello world";

------
file2.js
alert(msg);
-----------------

I want to know if posible
in my index.html page i have
only
<Script type="text/javascript" Language="JavaScript" Src="file2.js
"></script>

<script type="text/javascript" src="file2.js"></script>

The attribute 'language' is of no utility (in any browser).
i want that file1.js included file2.js

By wich way ?
(what will tell to file1 to load file2)
i want the scope function of file1 ,"know" the scope of file2.js

with out contain this '<Script type="text/javascript"
Language="JavaScript" Src="file1.js "></script>'

in my index.html

<script type="text/javascript" src="file1.js"></script>

file1.js :
==========
var msg = 'hello';
document.write('<script type="text/javascript" src="file2.js">'+
'<\/script>');
//end script

or :

file1.js :
==========
var msg = 'hello';
function domLoadJS(file) {
var s = document.createElement('SCRIPT');
s.type = 'text/javascript';
s.src = file;
document.getElementsByTagName('HEAD')[0].appendChild(s);
}
// action (that can be made from html (ie: onclick in a button))
domLoadJS('file2.js');
//end script


But I don't see where is the interest to have that insteed of the normal
way that we are sure it works while calling a new script using JS could
fail with one or another browser.
I think that discusion came a lot of time here, try to see in archives
and in the FAQ <http://jibbering.com/faq/>.
 
T

Thomas 'PointedEars' Lahn

jaco said:
I have two js files

file1.js contain
var msg="Hello world";

Should be

window.alert(msg);

Even a feature test prior to call is in order.
-----------------

I want to know if posible
in my index.html page i have
only
<Script type="text/javascript" Language="JavaScript" Src="file2.js
"></script>


i want that file1.js included file2.js
i want the scope function of file1 ,"know" the scope of file2.js

Scope doesn't enter into it. All such includes share the same global scope.
with out contain this '<Script type="text/javascript"
Language="JavaScript" Src="file1.js "></script>'

Lose the `Language' attribute; the `language' attribute has been deprecated
long since (HTML 4.0, 1997-12-18 CE) in favor of `type', and was never
really necessary.

Lowercase all element type identifiers and attribute names; that makes DOM
scripting a lot easier, and is required for Valid XHTML, should you want to
declare and use it (later).
in my index.html

Possible, but unreliable. Google `loadScript', or RTSL of YUI, Google Maps
v3 aso. And read the FAQ: <http://jibbering.com/faq/#posting> pp.


PointedEars
 
J

Jeremy J Starcher

The attribute 'language' is of no utility (in any browser).

Not accurate. In particular 'language' attribute can be specify
"Javascript1.2" in many browsers. (Version 1.2 has some major and non-
trivial differences.)

Back to the other discussion ...

it is better to say that the Language attribute is not needed in modern
scripting.


Dynamic loading of script elements, either by document.write or creating
new script elements is fragile and their run-time execution cannot be
assured. IMHO, you are better to avoid them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top