Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Import JavaScript in JavaScript File

Import JavaScript in JavaScript File

Scheduled Pinned Locked Moved Web Development
javascripttoolshelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ahmet GULBAY
    wrote on last edited by
    #1

    Hi everybody, I need to call/include/import a JavaScript file (*.js) in another JavaScript (*.js) file. How can i do this. I tried to do writing a line in script file like: document.write(""); But this method writes the line to the document so i cannot use/call functions from another files which are stored in different folders. Thanks for your help.

    L S 2 Replies Last reply
    0
    • A Ahmet GULBAY

      Hi everybody, I need to call/include/import a JavaScript file (*.js) in another JavaScript (*.js) file. How can i do this. I tried to do writing a line in script file like: document.write(""); But this method writes the line to the document so i cannot use/call functions from another files which are stored in different folders. Thanks for your help.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Ahmet GULBAY wrote:

      I need to call/include/import a JavaScript file (*.js) in another JavaScript (*.js) file. How can i do this.

      I had no idea so I Googled: Javascript include and found this on the first page of results[^]!

      led mike

      1 Reply Last reply
      0
      • A Ahmet GULBAY

        Hi everybody, I need to call/include/import a JavaScript file (*.js) in another JavaScript (*.js) file. How can i do this. I tried to do writing a line in script file like: document.write(""); But this method writes the line to the document so i cannot use/call functions from another files which are stored in different folders. Thanks for your help.

        S Offline
        S Offline
        Shog9 0
        wrote on last edited by
        #3

        You're on the right track - but instead of writing to the document, create the <script> element using document.createElement(), set the attributes programatically, and then attach it to the document. If you want an example... or a robust, ready-to-use implementation... check out the jQuery getScript function[^].

        Citizen 20.1.01

        'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'

        J 1 Reply Last reply
        0
        • S Shog9 0

          You're on the right track - but instead of writing to the document, create the <script> element using document.createElement(), set the attributes programatically, and then attach it to the document. If you want an example... or a robust, ready-to-use implementation... check out the jQuery getScript function[^].

          Citizen 20.1.01

          'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'

          J Offline
          J Offline
          JohnFernandez
          wrote on last edited by
          #4

          Try this:

          S 1 Reply Last reply
          0
          • J JohnFernandez

            Try this:

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #5

            Script tags aren't parsed in Javascript files. I assume if he knew what needed to be loaded up-front, then he'd put that in the HTML though.

            Citizen 20.1.01

            'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups