Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 16th, 2005, 03:23 PM
Authorized User
 
Join Date: Oct 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default To include a js file into another js file

Hi All,

What is syntax to include a .js file into another .js file. I just for got how to do it.

Thanks,

John

 
Old August 16th, 2005, 03:31 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

    document.write("<script type='text/javascript' src='/js/libraries/css_query/css_query.js'></"+"script>");

Do this outside of a function, so that it happens before the page completely loads, otherwise, you'll replace the content of the current document.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old August 16th, 2005, 04:05 PM
Authorized User
 
Join Date: Oct 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for you help. I tried both statements below but they did not work. Any other suggestions?

document.write("<Script type=text/JavaScript src='Cookies.js'></Script>");

<Script type ="text/JavaScript" src="Cookies.js"></Script>

John

 
Old August 17th, 2005, 12:20 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Jdang67!!

 **** test.html********
<Script type ="text/JavaScript" src="first.js"></Script>

*************first.js********
 document.write("<script type='text/javascript' src='css_query.js'> <\/script>");
***********css_query.js*****
alert("hii") ;

Note:- May be in ur actual code you are embeding <script> tag within another <script> tag without closing it.i.e </script>

Hope this will help you

Cheers :)

vinod
 
Old February 28th, 2008, 03:32 AM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

using document.write a good solution but there is problem with it if you don't use it carefully.
Consider you want to use "1.js" in "2.js". and consider these tow simple file:
---------- 1.js -------------
alert("1");
-----------------------------

and

---------- 2.js -------------
document.write('<script language="javascript" src="1.js"></script>');
alert("2");
-----------------------------

in this case if you include "2.js" in your html file both file will load but your browser while show 2 before 1 and I'm sure it's not your desire.

To Solve the problem use these three file instead:
---------- 1.js -------------
alert("1");
-----------------------------

and

-------- 2_main.js ----------
alert("2");
-----------------------------

and

----------- 2.js ------------
document.write('<script language="javascript" src="1.js"></script>');
document.write('<script language="javascript" src="2_main.js"></script>');
-----------------------------

then include just "2.js" in your html file. It will alert 1 then will alert 2 and the sequence will be your desire.

Take care budies.






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to include .js file in .aspx page shanwaj ASP.NET 2.0 Basics 13 March 11th, 2008 07:36 AM
asp file into a javascript file (js)? jstewie Javascript How-To 2 August 25th, 2005 08:32 AM
convert a js file from a asp file - change format jstewie Javascript How-To 0 July 21st, 2005 08:57 AM
.js file question savoym Javascript How-To 1 May 17th, 2004 02:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.