Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| 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 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 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"
}

 
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
Default

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:
    Code:
    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)




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 03: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





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