Can someone help, I think it is simple.

B

broadband-engine

Hi

Can someone help, I think it is simple. I want to call the script that is currently in the head into the page from another file in order to tidy up the head section. Currently getting an error. Do I have to do something with the <body> tag if I am calling the script in???????

Code:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="---.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages&#40;&#41; &#123; //v3.0
  var d=document; if&#40;d.images&#41;&#123; if&#40;!d.MM_p&#41; d.MM_p=new Array&#40;&#41;;
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for&#40;i=0; i<a.length; i++&#41;
    if &#40;a&#91;i&#93;.indexOf&#40;"#"&#41;!=0&#41;&#123; d.MM_p&#91;j&#93;=new Image; d.MM_p&#91;j++&#93;.src=a&#91;i&#93;;&#125;&#125;
&#125;

function MM_swapImgRestore&#40;&#41; &#123; //v3.0
  var i,x,a=document.MM_sr; for&#40;i=0;a&&i<a.length&&&#40;x=a&#91;i&#93;&#41;&&x.oSrc;i++&#41; x.src=x.oSrc;
&#125;

function MM_findObj&#40;n, d&#41; &#123; //v4.01
  var p,i,x;  if&#40;!d&#41; d=document; if&#40;&#40;p=n.indexOf&#40;"?"&#41;&#41;>0&&parent.frames.length&#41; &#123;
    d=parent.frames&#91;n.substring&#40;p+1&#41;&#93;.document; n=n.substring&#40;0,p&#41;;&#125;
  if&#40;!&#40;x=d&#91;n&#93;&#41;&&d.all&#41; x=d.all&#91;n&#93;; for &#40;i=0;!x&&i<d.forms.length;i++&#41; x=d.forms&#91;i&#93;&#91;n&#93;;
  for&#40;i=0;!x&&d.layers&&i<d.layers.length;i++&#41; x=MM_findObj&#40;n,d.layers&#91;i&#93;.document&#41;;
  if&#40;!x && d.getElementById&#41; x=d.getElementById&#40;n&#41;; return x;
&#125;

function MM_swapImage&#40;&#41; &#123; //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for&#40;i=0;i<&#40;a.length-2&#41;;i+=3&#41;
   if &#40;&#40;x=MM_findObj&#40;a&#91;i&#93;&#41;&#41;!=null&#41;&#123;document.MM_sr&#91;j++&#93;=x; if&#40;!x.oSrc&#41; x.oSrc=x.src; x.src=a&#91;i+2&#93;;&#125;
&#125;
//-->
</script>
</head>

<body onLoad="MM_preloadImages&#40;'images/compare-credit-cards.jpg',
'images/compare-loans.jpg','images/compare-current-accounts.jpg',
'images/compare-savings-accounts.jpg','images/compare-utilities.jpg',
'images/compare-insurance.jpg','images/news.jpg'&#41;">

here is what the script is doing, it is swapping an image on mouseover.

Code:
<a href="http&#58;//www.quote-engine.com/compare-credit-cards.html" onMouseOver="MM_swapImage&#40;'Image1','','images/compare-credit-cards.jpg',1&#41;" onMouseOut="MM_swapImgRestore&#40;&#41;"> [img]/images/compare-credit-cards1.jpg[/img]



Cheers
Phil
 

Ozzy

Founder of UKBF
UKBF Staff
  • Feb 9, 2003
    8,368
    11
    3,518
    Northampton, UK
    bdgroup.co.uk
    You need to close the <a> tag at the end of the URL and then open the image tag. Then the onMouseOver and MouseOut javascript is within the content of the <img> tag and not the <a> tag as it currently is. For example....

    <a href="http://www.quote-engine.com/compare-credit-cards.html"> /images/compare-credit-cards1.jpg
    </a>
     
    Upvote 0
    to remove the javascript from the page put the lines below into an external file eg myscript.js


    Code:
    <script language="JavaScript" type="text/JavaScript"> 
    <!-- 
    function MM_preloadImages&#40;&#41; &#123; //v3.0 
      var d=document; if&#40;d.images&#41;&#123; if&#40;!d.MM_p&#41; d.MM_p=new Array&#40;&#41;; 
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for&#40;i=0; i<a.length; i++&#41; 
        if &#40;a&#91;i&#93;.indexOf&#40;"#"&#41;!=0&#41;&#123; d.MM_p&#91;j&#93;=new Image; d.MM_p&#91;j++&#93;.src=a&#91;i&#93;;&#125;&#125; 
    &#125; 
    
    function MM_swapImgRestore&#40;&#41; &#123; //v3.0 
      var i,x,a=document.MM_sr; for&#40;i=0;a&&i<a.length&&&#40;x=a&#91;i&#93;&#41;&&x.oSrc;i++&#41; x.src=x.oSrc; 
    &#125; 
    
    function MM_findObj&#40;n, d&#41; &#123; //v4.01 
      var p,i,x;  if&#40;!d&#41; d=document; if&#40;&#40;p=n.indexOf&#40;"?"&#41;&#41;>0&&parent.frames.length&#41; &#123; 
        d=parent.frames&#91;n.substring&#40;p+1&#41;&#93;.document; n=n.substring&#40;0,p&#41;;&#125; 
      if&#40;!&#40;x=d&#91;n&#93;&#41;&&d.all&#41; x=d.all&#91;n&#93;; for &#40;i=0;!x&&i<d.forms.length;i++&#41; x=d.forms&#91;i&#93;&#91;n&#93;; 
      for&#40;i=0;!x&&d.layers&&i<d.layers.length;i++&#41; x=MM_findObj&#40;n,d.layers&#91;i&#93;.document&#41;; 
      if&#40;!x && d.getElementById&#41; x=d.getElementById&#40;n&#41;; return x; 
    &#125; 
    
    function MM_swapImage&#40;&#41; &#123; //v3.0 
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for&#40;i=0;i<&#40;a.length-2&#41;;i+=3&#41; 
       if &#40;&#40;x=MM_findObj&#40;a&#91;i&#93;&#41;&#41;!=null&#41;&#123;document.MM_sr&#91;j++&#93;=x; if&#40;!x.oSrc&#41; x.oSrc=x.src; x.src=a&#91;i+2&#93;;&#125; 
    &#125; 
    //--> 
    </script>

    put the following lines in the html in its place

    Code:
    <SCRIPT LANGUAGE="JavaScript" SRC="myscript.js">
    </SCRIPT>

    all done
     
    Upvote 0

    Latest Articles