Skip navigation
TheirRNoavailableESC
Currently Being Moderated

import a javascript??

Apr 27, 2013 7:56 PM

Tags: #javascript

Hi I really need to know if its possible to import a .js to a new html page like you would a .css, if yes, HOW?

Could someone please help? I spent all day all this, I am ither really dumb or really blind.

 
Replies
  • Currently Being Moderated
    Apr 28, 2013 4:57 AM   in reply to TheirRNoavailableESC

    Put this in your code in the <head> section:

     

    <script type="text/javascript" src="put the location of the source file here"></script>

     

    Some people like to add language="javascript" too but it isn't an absolute necessity.

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Apr 28, 2013 8:13 AM   in reply to TheirRNoavailableESC

    @TheirRno....: CF solution will work. But depending on what type of .js file you're trying to incorporate, you could either load it within your <head> section or anywhere towards the very bottom of your page before closing </body> tag. The difference is pageload times. Javascript calls at the very bottom will load your actual webpage much faster. Again, this may not work at all times. If your webpage uses a certain function that is controlled using a .js file, that file may need to be loaded in <head> tag.

     

    But, if you're using a plug-in that you're trying to run only after your page completely finishes loading, these scripts can be at the very bottom.

     

    This is a generic structure of a HTML5 website with CSS, JS and jQuery library:

     

    <!doctype html>

    <head>

         <meta> <!--All metatags here-->

         <title>Title here</title>

         <link href="path/to/your/stylesheet.css" type="text/css"> <!--Your CSS files can be included here-->

         <script src="path/to/your/jquery/library.js" type="text/javascript"> <!--Your jQuery library can be included at the very beginning as all jQuery plugins you'll use will rely on the library-->

    </head>

    <body>

         YOUR MAIN WEBSITE CONTENT HERE

    <script src="path/to/your/plugin.js" type="text/javascript"> <!--Your plugins can be loaded here so the webpage loads faster-->

    </body>

    </html>

     

    And like CF says, the type definition is not necessary, but is definitely recommended to ensure browsers dont go into 'quirks' mode. Also to make your webpage W3 compliant.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 28, 2013 10:37 AM   in reply to TheirRNoavailableESC
     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Apr 28, 2013 9:04 PM   in reply to TheirRNoavailableESC

    Java & JavaScript are like apples and oranges. 2 completely different things. What you use normally for webpages with .js extension is JavaScript.

     

    when I made a responsive html and it keeps giving me errors when I try to add it

    What errors did you get?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points