Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4045244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:23:56+00:00 2026-05-20T13:23:56+00:00

I would like to send some javascript from one file to another in my

  • 0

I would like to send some javascript from one file to another in my own server. For example on file 1 I have the following code:

<script>

   alert("Hey There!");

</script>

I want to send this code to file 2, so that the alert happens on file 2. Imagine File 2 had already loaded, I want to perform some processing on File 1 and based on the result of said processing I want to send something to File 2.

File 2 should not be sending any requests to File 1, File 1 should be doing all the sending, and File 2 should receive the message without page refresh.

Is this possible?

EDIT

Imagine I have 3 files (2 html and 1 js). File A has already loaded, there’s nothing in there. The js file is call “sayHello.js”, it has the following content:

alert('Indeed 10 is less than 100');

File B has the following content:

if (10 < 100) {

   // attach the js file "sayHello.js" to File A

}

How would I be able to attach the js file to File A from File B (using the jQuery.getScript() method) and have the script execute on File A?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:23:56+00:00Added an answer on May 20, 2026 at 1:23 pm

    Generally – you have to separate in your thinking what runs where – what code runs on the server and what code runs on the browser.
    In the more complicated cases – the JavaScript that runs on the client would be generated by a server page that generates relevant JavaScript in according to the request context – in this case you have to remember well the order of operations.

    Taking the simple premise that you refer communication on the client between code – you should keep in mind that the files do not process anything – they load JavaScript code to the root scope of the browser, and the browser executes it.
    In that manner you have to separate between commands and definitions, while every file that loads can access all the “members” that were introduced to the root scope by formerly loaded scripts (the right name is for these members is symbols, i.e – all functions and variables).

    Discussing your two files –
    File 2 looks like a “main” to me, and file 1 looks like a “utility/library” to me.

    So, instead of executing code on the root scope on file 1 – you have to define functions – where these functions would be accessible to file 2.

    Your HTML:

    <script src="File1.js"></script>
    <!-- if you need to exectute the code in File1 - you can call it like this -->
    <script>
       actionInFile1()
    </script>
    <script src="File2.js"></script>
    

    File 1:

    function actionInFile1(){
        alert("Hey There!")
    }
    

    File 2:

    actionInFile1();
    

    Having that in mind – I think that what you’re describing is a dynamic load of scripts to the client.

    Adding a second script on the fly to the current page, using jQuery is done using
    http://api.jquery.com/jQuery.getScript/

    Now – for a more complex example –
    Your HTML

    <script src="jQuery.....js"></script>
    <script src="File1.js"></script>
    <button value="   go   "  onclick="toTrick()">
    

    File1.js

    function doStuff(){
         alert("Hey there!");
    }
    

    File2.js

    function toTrick(){
        $.getScript('ajax/test.js'
                   , function() {
                         doStuff();             
                     }
                   );
    }
    

    EDIT:

    What you need to read about is variables scope in JavaScript.

    File A has the following content:

    function notify(){
        alert('Indeed 10 is less than 100');
    }
    notify();
    

    File B has the following content:

    if (10 < 100) {
         //notify is defined in file A, however it will be accessible here
         // as long as file A is loaded before file B.
         notify();
    }
    

    HTML has the following content:

     <script src="FileA.js"></script><!-- defines "notify" and executes it immediately -->
     <script src="FileB.js"></script><!-- reuses notify() -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get a sum from a column, with and without a
I would like to remove/delete a migration file. How would I go about doing
I would like to update my SQL lite database with the native update-method of
(please excuse that I didn't use aliases). I would like my query output to
I want to have generalised email templates. Currently I have multiple email templates with
My question is about memory use and objects in actionscript 2. If I have
I'm trying to write test harness for part of my Android mapping application. I
I want the messagebox to only show if the number is equal to 0.
There doesn't seem to be any tried and true set of best practices to
I know its probably possible, but is it practical and doable to try and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.