Click to See Complete Forum and Search --> : How to call a script with HTML?


Wicked
04-21-2006, 02:01 PM
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..

<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?

TheBearMay
04-21-2006, 02:07 PM
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.

Wicked
04-21-2006, 02:17 PM
Your my hero thanks..

felgall
04-21-2006, 04:24 PM
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.