473,396 Members | 1,760 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,396 software developers and data experts.

including a javascript file in another.. HOW!?!?

how do you include a javascript file A in another javascript file B inorder to be able to use the functions in A from B.

i thought the code in javascript file B would be like this...

<script src="chrome://followmylink/contents/fileA.js">

...code in B where i will be using the functions from B ...

</script>

Also is there a way how you would define a class?

is it like this:

var ClassA = new Object {
//..attributes..
this.attr1 = "";
}

//functions
ClassA.method1 = function() {
//.....code......
}

If so how should I call it from file A if I put it in file B

Thanks very much!!!
Apr 27 '06 #1
3 2181
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. var head = document.getElementsByTagName('head')[0];
  2. var script = document.createElement('script');
  3. script.setAttribute('type','text/javascript');
  4. script.setAttribute('src',nameOfFile);
  5. head.appendChild(script);
or using document.write (and escaping the ending script tag).
Mar 27 '08 #2
pronerd
392 Expert 256MB
how do you include a javascript file A in another javascript file B inorder to be able to use the functions in A from B.

i thought the code in javascript file B would be like this...

<script src="chrome://followmylink/contents/fileA.js">

...code in B where i will be using the functions from B ...

</script>
The code in the B file goes out side fo the script tag from the A file. See below.

Expand|Select|Wrap|Line Numbers
  1. <script src="chrome://followmylink/contents/fileA.js"></script>


Also is there a way how you would define a class?
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.     function myClassFile(){
  3.  
  4.         this.someVar = 'This is a String';
  5.  
  6.         this.someMethod = new function(){
  7.             .....
  8.             .....
  9.         }
  10.     }
  11. <script/>
  12.  


If so how should I call it from file A if I put it in file B
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.  
  3.     document.write('<script src="chrome://followmylink/contents/fileA.js"></script>');
  4.  
  5.  
  6.     var myClassInstance = new myClassFile();
  7.  
  8.     myClassInstance.someMethod();
  9.  
  10. <script/>
  11.  
Mar 27 '08 #3
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.  
  3.     document.write('<script src="chrome://followmylink/contents/fileA.js"></script>');
  4.  
Browsers may close the script on encountering "</script> within the script, so it should be escaped, e.g. <\/script>.
Mar 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Fabian | last post by:
Well, what can I say...I really hate Javascript. I am not programming as profession but I sometimes work with PHP with MySQL, ASP with Ms Access/SQL Server. I have done something in VB and when...
3
by: Joseph Ferris | last post by:
Hello everyone. I recently reloaded my system, and I am now having problems getting one of my client's sites running. I pulled a copy of the development tree for the project out of subVersion...
2
by: griffithsj_520 | last post by:
I have to create a web page to give to clients that is shipped on CD. The idea is that they would open the page and it would display in their web browser. What this will do is to provide a list...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
3
by: Mr. Roper | last post by:
I'm pretty weak when it comes to Java script, hopefully someone will take mercy on my sole and explain this to me. How come on the following HTML page, when I have my first script tag commented...
38
by: Neo Geshel | last post by:
I am seeking a method to load one JS file directly into another, *without* having to dynamically write <scripttags. Is there any method whereby I can call only one external JS file using a ...
22
by: Christopher Nelson | last post by:
I have a little menu system which essentially takes HTML like: <div id='foo'></div> and retrieves foo.shtml from the server and inserts it inside the <div>. But sometimes I'd like foo.shtml...
1
by: hakyns3 | last post by:
how do you include a java script file in another java script file <br> <script language="javascript" src="searchSiteArray.js"></script> does not seem to work
1
by: davidemazza82 | last post by:
Hi all, I got an from IE 7.0.5730.11 when moving the <script src="..." type="text/javascript" /tag from the <headpart to the <bodysection of a HTML file. Is not possibile to include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.