How to place the .js file

Discussion in 'JavaScript' started by josechukkiri, May 9, 2011.

  1. #1
    I have uploaded a file saved in .js format. How I can place it with my html index page? Kindly help me.
     
    josechukkiri, May 9, 2011 IP
  2. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #2
    The best practise is include tag SCRIPT into HEAD tag in HTML structure. Here is an example:

    
    <html>
    
      <head>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
      </head>
    
      <body>
      body here...                                    
      </body>
    
    </html>
    
    Code (markup):
    - attribute type defines that in the file is javascript code
    - src is relative path /absolute URL to your js file at webhosting
     
    Jan Novak, May 9, 2011 IP
  3. josechukkiri

    josechukkiri Well-Known Member

    Messages:
    476
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    158
    #3
    Hi Jan Novak
    , thanks for your response. I need the script should be located in a particular position on the index file.If I am placing the include tag on the body section , would be OK. If I am copy paste the code on the body, it will work. But I want the updates in the .js file itself. So there is no need to go to the index file to edit the data.
     
    josechukkiri, May 9, 2011 IP
  4. KittyS

    KittyS Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't have the answer but try stackoverflow.com - I love this site for help getting to the bottom of a technical issue. Good luck!
     
    KittyS, May 9, 2011 IP
  5. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Yes, this is possible too. You can "position" SCRIPT tag everywhere you want.

    If you don't see fresh results, try CTRL+F5 in browser to reload fresh sources from server. If you don't modify index file, it is a chance that browser load old .js file from browser cache.
    Please explain more your problem, add source code and expected results to help you more.
     
    Jan Novak, May 9, 2011 IP
  6. andrewgail

    andrewgail Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The JS file type is primarily associated with JavaScript. The files are generally text files. Also, This file type can become infected and should be anxiously scanned if anyone sends you a book with this extension.
     
    andrewgail, May 13, 2011 IP
  7. Voynex

    Voynex Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Include of the JavaScript in the hard of the document like Jan Novak has posted will work pretty well for what you need.
     
    Voynex, May 24, 2011 IP