SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Nov 2002
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I link to a .js script like I link to a.css file?

    How do I link to a Javascript script like I link to a.css file?

    This is the way my code looks, (this does work):
    Code:
    <script language="JavaScript">function showObj(objid)
    {
    	parent.frames['there'].document.getElementById(objid).style.display='block';
    	parent.frames['there'].document.getElementById(objid).style.zindex='5';
    }</script>
    </head>
    <body onload="showObj('Pg'+parent.document.forms['chapage'].elements['pge'].value);">
    I have never been able to get my Javascript into a .js file and still have it work. Any help in clarifiing the issue for me will be of great help.


    -berzerko

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    In your HTML page (in the <head> of the document):
    HTML Code:
    <script type="text/javascript" src="/myscript.js"></script>
    myscript.js:
    Code:
    function showObj(objid)
    {
    	parent.frames['there'].document.getElementById(objid).style.display='block';
    	parent.frames['there'].document.getElementById(objid).style.zindex='5';
    }
    That's all there is to it.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2002
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    In your HTML page ...

    ...That's all there is to it.
    I can't believe it! It really worked. I have no idea what I was trying to do before. But this did the job. Much thanks!

    -berzerko

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by berzerko
    I can't believe it! It really worked. I have no idea what I was trying to do before. But this did the job. Much thanks!

    -berzerko
    You may have left the <script> tags in the JS file, a common error when people first start using external JS files.


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
  •