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
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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 11th, 2008, 10: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, 12:12 PM
joefawcett's Avatar
Wrox Author
Points: 9,731, Level: 42
Points: 9,731, Level: 42 Points: 9,731, Level: 42 Points: 9,731, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,068
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)
Reply With Quote
Reply


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 07: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 12:35 PM
asp file into a javascript file (js)? jstewie Javascript How-To 2 August 25th, 2005 09:32 AM
function in linked js file 'is not defined' John K. King Javascript 4 May 7th, 2004 10:04 PM



All times are GMT -4. The time now is 09:23 PM.


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