SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible to link to javascript held within another file, in a similar way to linking to external CSS?

    I understand that the 'calls must be in place in the html etc', but it would make things much easier if I could have one external 'common JavaScript file'.

    If it is possible could someone give me an example of the correct method of doing this - eg and example for a link to a CSS file would be this:


    What is the equivilent for JS? - If possible.
    <style type="text/css">
    <!--
    <link rel="stylesheet" href="../css/standardstyles.css">
    -->
    </style>

    Cheers in advance


  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    First off, your CSS example is incorrect. All of the lines in red should be removed, and the attribute in blue should be added.

    Code:
    <style type="text/css"> 
    <!--
    <link rel="stylesheet" type="text/css" href="../css/standardstyles.css"> 
    --> 
    </style>
    The equivalent for external JavaScript files is as follows:

    Code:
    <script language="JavaScript" type="text/javascript" src="scriptfile.js"></script>
    You can place alternate content (to be displayed if the browser does not support JavaScript) between the <script> and </script> tags if you wish.

    Note that scriptfile.js should just contain JavaScript. No <script> tags or <!-- html comments -->.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for the help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •