www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to call a script with HTML?

  1. #1
    Join Date
    Dec 2004
    Location
    California
    Posts
    45

    Exclamation How to call a script with HTML?

    Ok I have a website header that I want to call into the page via one line of code such as using a id="myheaderhtml" instead of using the 15 lines of code that originally makes the header. So I want to call the the script from another location. Ill show you exactly what Im talking about..

    The code I need to link is below..

    Code:
    <script language="JavaScript" type="text/javascript">
    <!-- 
    var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if(hasRightVersion) {  // if we've detected an acceptable version
        var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
        + 'width="761" height="224"'
        + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
        + '<param name="movie" value="header.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ff9900" />'
        + '<embed src="header.swf" quality="high" bgcolor="#ff9900" '
        + 'width="761" height="224" name="header" align="middle"'
        + 'play="true"'
        + 'loop="false"'
        + 'quality="high"'
        + 'allowScriptAccess="sameDomain"'
        + 'type="application/x-shockwave-flash"'
        + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
        + '</embed>'
        + '</object>';
        document.write(oeTags);   // embed the flash movie
      } else {  // flash is too old or we can't detect the plugin
        var alternateContent = 'You do not have the needed plugins to view this website header.'
      + 'This content requires the Macromedia Flash Player.'
      + '<a href=http://www.macromedia.com/go/getflash/>Get Flash';
        document.write(alternateContent);  // insert non-flash content
      }
    // -->
    </script>
    So where can I put that code and how could I link to the code so that when I call an ID name or something by using only a line of code it would be the same as if all of the above code was there in the document. Is this possible?

  2. #2
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    If you put that into a separate file and call it, for example, header.js, then you can just place the line:

    <script type="text/javascript" src="header.js"></script>

    into your html.
    54 68 65 42 65 61 72 4D 61 79

  3. #3
    Join Date
    Dec 2004
    Location
    California
    Posts
    45
    Your my hero thanks..

  4. #4
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    You also need to replace the following lines:

    document.write(oeTags); // embed the flash movie
    document.write(alternateContent); // insert non-flash content

    with

    document.getElementById('myheaderhtml').innerHTML = oeTags;
    document.getElementById('myheaderhtml').innerHTML = alternateContent;

    respectively.
    Stephen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles