Include file in javascript 
Author Message
 Include file in javascript

Hello all,

I am coding in javascript under WindowScriptingHost.
The question is :
How can I include a files in my script?
Someting similar to the include command in C.

Thanks,
Juan



Sun, 22 Feb 2004 21:31:12 GMT  
 Include file in javascript
Using Windows Script Files
http://msdn.microsoft.com/scripting/windowshost/doc/wsadvantagesofws.htm

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> Hello all,

> I am coding in javascript under WindowScriptingHost.
> The question is :
> How can I include a files in my script?
> Someting similar to the include command in C.

> Thanks,
> Juan



Mon, 23 Feb 2004 04:35:26 GMT  
 Include file in javascript
"Low tech" approach:

// FileName: MyMainScript.js
///////////////////////////////////////////////////////////////////////

if (WScript.ScriptName == "MyMainScript.js") {
 var oFSO = new ActiveXObject("Scripting.FileSystemObject");
 var sCurPath = oFSO.GetParentFolderName(WScript.ScriptFullName);
 var sPath_1 = oFSO.BuildPath(sCurPath, "MyOtherScript_1.js");
 var sPath_2 = oFSO.BuildPath(sCurPath, "MyOtherScript_2.js");
 // More script paths...

 // "Include" MyOtherScript_1.js
 try {
  eval (oFSO.OpenTextFile(sPath_1, 1).ReadAll());
 } catch (e) {
  var gsMsg = e.description + ": \n\n";
  gsMsg += "\"" + sPath_1 + "\"";
  WScript.Echo(gsMsg);
  WScript.Quit();
 }

 // "Include" MyOtherScript_2.js
 try {
  eval (oFSO.OpenTextFile(sPath_2, 1).ReadAll());
 } catch (e) {
  var gsMsg = e.description + ": \n\n";
  gsMsg += "\"" + sPath_2 + "\"";
  WScript.Echo(gsMsg);
  WScript.Quit();
 }

 // ...

All "included" scripts should be in the same folder with "MyMainScript.js".

But quite honestly *.wsf and:
<script language="JScript" src="Lib\MyOtherScript_1.js"/>
does the better ('cuz cleaner in approach) job.

Branimir

Quote:

> Hello all,

> I am coding in javascript under WindowScriptingHost.
> The question is :
> How can I include a files in my script?
> Someting similar to the include command in C.

> Thanks,
> Juan



Mon, 23 Feb 2004 21:10:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Include file for Javascript in WSH

2. Include JavaScript file in another include file

3. Include JavaScript code within external CSS files

4. how to pass parameters in an include file which is included in an asp page

5. Javascript includes - OK in Pocket PC?

6. Include with Javascript

7. Include-Command in Javascript ?!??

8. Problem Including ASP in Javascript

9. JavaScript Include

10. JavaScript: Navigate site via dropdown on an include page

11. #INCLUDE in Javascript

12. including javascript

 

 
Powered by phpBB® Forum Software