Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old July 11th, 2008, 09:49 AM
Authorized User
Join Date: Mar 2008
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to run a .js file from a javascript function

Hello everyone

This may be a silly question.
Is there a way to run a .js file ie call a .js file from another folder from inside a javascript function?

for eg..can I do this -->

function callJsFile()
 //call a .js file and execute the code in it at //src="../js/somejavascript.js"

Reply With Quote
  #2 (permalink)  
Old July 11th, 2008, 11:12 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

There are a few options depending on how you are running the first file.
  • You can create an instance of WSCript.Shell and use its Run method to call CScript MyFile.js. This is unlikely to work in a browser as WScript.Shell is not safe for scripting:
    var oShell = new AactiveXObject("WScript.Shell");
    oShell.Run("myFile.js", 1, true);
    (You'll need to look at the documentation for the methods full syntax.
  • You can switch to a wsf format, this allows multiple files within one main file, including different languages, this is what I use for most serious scripts
  • You can host within a web page, include the second file and just call whichever functions you need
As I said you need to define your calling environment.


Joe (Microsoft MVP - XML)
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute Stored Procdure from Javascript(JS) file AbrarNazeer Javascript How-To 1 March 18th, 2008 06:39 AM
To include a js file into another js file jdang67 Javascript 4 February 28th, 2008 02:32 AM
make .js file run as fast as possible crmpicco Javascript 4 October 24th, 2005 11:35 AM
asp file into a javascript file (js)? jstewie Javascript How-To 2 August 25th, 2005 08:32 AM
function in linked js file 'is not defined' John K. King Javascript 4 May 7th, 2004 09:04 PM

All times are GMT -4. The time now is 01:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.