Will SSI put code inside the HEAD?

liunx

Guest
<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=19346&highlight=SSI+javascript">http://www.htmlforums.com/showthread.ph ... javascript</a><!-- m --><br />
<br />
I read the above thread but didn't quite follow and don't know what is meant in one reply by "separate into .js files." I am thinking I need to learn more about javascript... In the meantime: <br />
<br />
I've used SSI for htm files successfully. I have a pop-up window script that has a lot of code to go into the head. I'd like to put this in a separate file and be able to refer to it with one line of code, as with SSI. This is the script that goes inside the HEAD:<br />
<br />
<br />
<!--BEGIN Pop-up Images Script--><br />
<SCRIPT Language="JavaScript"><br />
<!--<br />
// Copyright 1999 - 2002 by Ray Stott, Pop-up Images Script ver 2.0<br />
// OK to use if this copyright is included<br />
// Script is available at <!-- m --><a class="postlink" href="http://www.crays.com/jsc">http://www.crays.com/jsc</a><!-- m --><br />
<br />
var pic = null<br />
var popImg = null // use this when referring to pop-up image<br />
var picTitle = null<br />
var imgCount = 0<br />
var imgWinName = "popImg"<br />
<br />
function openPopImg(picName, windowTitle, windowWidth, windowHeight){<br />
closePopImg()<br />
picTitle = windowTitle<br />
imgWinName = "popImg" + imgCount++ //unique name for each pop-up window<br />
popImg = window.open(picName, imgWinName,<br />
"toolbar=no,scrollbars=no,resizable=no,width="<br />
+ (parseInt(windowWidth)+20) + ",height="<br />
+ (parseInt(windowHeight)+15))<br />
}<br />
function closePopImg(){ // close pop-up window if it is open<br />
if (navigator.appName != "Microsoft Internet Explorer"<br />
|| parseInt(navigator.appVersion) >=4) //do not close if early IE<br />
if(popImg != null) if(!popImg.closed) popImg.close()<br />
}<br />
function setStatus(msg){<br />
status = msg<br />
return true<br />
}<br />
//--><br />
</SCRIPT><br />
<br />
<SCRIPT Language="JavaScript1.1"><br />
<!--<br />
// for Netscape 3+ and IE 4+<br />
var priorPic = new Array()<br />
var noPic = 0<br />
var foundit = false<br />
<br />
function openPopImg(picName, windowTitle, windowWidth, windowHeight){<br />
var i = 0<br />
if(pic == picName && winOpen()){<br />
popImg.focus()<br />
}<br />
else{<br />
foundit = false<br />
for(i=0; i<=noPic; i++){<br />
if (priorPic == picName)<br />
foundit = true<br />
}<br />
pic = picName<br />
closePopImg()<br />
picTitle = windowTitle<br />
imgWinName = "popImg" + imgCount++ //unique name for each pop-up window<br />
if(!foundit){<br />
priorPic[noPic++] = pic<br />
}<br />
popImg = openPopImgWin(imgWinName, windowWidth, windowHeight)<br />
}<br />
}<br />
function openPopImgWin(imgWinName, windowWidth, windowHeight){<br />
var winFeatures = "toolbar=no,scrollbars=no,resizable=no,width="<br />
+ windowWidth + ",height=" + windowHeight<br />
return window.open("pimg.htm", imgWinName, winFeatures)<br />
}<br />
function winOpen(){<br />
if(popImg != null){<br />
if(popImg.closed != true) return true; else return false<br />
}<br />
else<br />
return false<br />
}<br />
//--><br />
</SCRIPT><br />
<br />
<SCRIPT Language="JavaScript1.2"><br />
<!--<br />
// Use this function to control placement of pop-up window<br />
// in Netscape 4+ and Internet Explorer 4+<br />
function openPopImgWin(imgWinName, windowWidth, windowHeight){<br />
var leftX = 20 // distance of window's left side from left of screen<br />
var topY = 20 // distance of window's top side from top of screen<br />
var winFeatures = "toolbar=no,scrollbars=no,resizable=no,width="<br />
+ windowWidth + ",height=" + windowHeight<br />
if (leftX>0){<br />
winFeatures += ",screenX=" + leftX + ",left=" + leftX<br />
+ ",screenY=" + topY + ",top=" + topY<br />
}<br />
return window.open("pimg.htm", imgWinName, winFeatures)<br />
}<br />
//--><br />
</SCRIPT><br />
<!--END Pop-up Images Script--> <br />
<br />
This is what goes in the BODY to call up the script and make the pop-up window:<br />
<br />
<A HREF=http://www.htmlforums.com/archive/index.php/"JAVASCRIPT:openPopImg('photos/belo/kidsanct.jpg', 'Like 300 children in one room!!', '640', '240')"<br />
onMouseOver="return setStatus('Click to display picture.')"<br />
onMouseOut="return setStatus('')">CLICK HERE</A> {this made a smiley but it doesn't really haha}<br />
<br />
I would like to put the script that goes in the HEAD in a separate file so it could be used on several pages without making the head so big [gotta keep the ego down on my files]. Would this work with SSI or would it be better another way? Thank you for your help.<!--content-->put everything in a seperate file and call it "whatever.js"<br />
<br />
than make sure you don't have and script tags in that file. so take all these out<br />
<br />
<script ... ></script><br />
<br />
as those can't go in there.<br />
<br />
then in the head section you want to add this<br />
<br />
<script scr="whatever.js" type="text/javascript"></script><br />
<br />
easy as that. and no SSI<!--content-->Wow, thank you, scoutt, that seems so easy!!! Just clarifying:<br />
<br />
There are 3 different scripts there. It will all be okay in one .js file?<!--content-->yup, it will be just fine since they are just functions.<!--content-->Don't forget to add type="text/javascript" to the HTML <script> tags too (just in case you missed that little extra detail in Scoutts posting).<!--content-->Scoutt and giz, thanks so much for you help, but I'm going to bother you one more time. I think I've followed scoutt's directions correctly. Double checked (measure twice, cut once). took out all the script references. <br />
<br />
The page looks fine, but the popup windows don't come up. Comment down at the bottom says "error on page." I also have a menu on the page uses javascript, but I can't see that this would be a problem since it worked fine before with the code directly in the head section. <br />
<br />
I think I just figured it out... a typo. <br />
<br />
<script scr="whatever.js" type="text/javascript"></script><br />
<br />
Should it not be <script src <br />
not<br />
<script scr ?? <br />
<br />
Okay, working fine now. Thanks for your help. I learned two lessons with this thread! :D<!--content-->Yeah, Scoutt needs a new keyboard (or to learn to slow down). It is src not scr, and I missed that too.<!--content-->Originally posted by giz <br />
Yeah, Scoutt needs a new keyboard (or to learn to slow down). It is src not scr, and I missed that too. <br />
yup, slow down, my bad :)<br />
<br />
good catch<!--content-->
 
Back
Top