SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    London, UK
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add javascripts together & call from external file

    My javascript skills are poor. I am trying to make it easier for search engine robots to scan my site - since some get confused by javascript.

    Could anyone tell me how to add alll my javascripts together and then place them in an external file so i can call from the <head> section of my website?

    You can see the javascripts in the <head> section at www.hostcompanies.com.

    I would really appreciate it if someone call show me show to do this.

    Thanks in advance for any help
    Add your web design / hosting companies to my directory - Web Hosting Directory
    Want to join our panel of experts? - Hosting Forums ( top right of forums -expert drop down box for more info ).

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take everything between all opening and closing SCRIPT tags and put in a separate file with a '.js' extension. Be sure to remove any html comment tags as well as the script tags themselves (no html allowed in .js files). Be careful about the menu script in the BODY - I'm not sure about its requirements. I would just leave the menu script as it is.

    In the HEAD, the following will 'include' your .js file into the current page.
    Code:
    <script type='text/javascript' src='myscripts.js'></script>
    In src='' you can use a relative or absolute path to the file, for example:
    Code:
    <script type='text/javascript' src='../scripts/myscripts.js'></script>

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    London, UK
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Well how do i...

    What id really like to know is if i can add these 2 javascripts together and then call them from 1 external file. Of do i have to create an individual external (js) file for each script.

    If anyone can show my how to add them together , that would be useful. I dont know how to exactly blend the two together. below are the two javascripts.

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    }
    //-->
    </script>
    And

    Code:
     <SCRIPT language=JavaScript type=text/javascript>
    <!--
    <!-- Begin
    function formHandler(form){
    var URL = document.form.site.options[document.form.site.selectedIndex].value;
    window.location.href = URL;
    }
    function expandDiv(tlll) {
    				what  = eval(tlll + "_menu");
    				if (what.style.display == "none") {
    						what.style.display = "";
    				} 
    else
     what.style.display = "none";
    		}
     var oldc = new Array;
     function cCell(r,m){
      if(!document.all) return;
      if(m){
       for(i=0;i<r.cells.length;i++){
       oldc[i]=r.cells[i].bgColor;
       r.cells[i].bgColor='D3D3D3';
       }
      }else{
       for(i=0;i<r.cells.length;i++){
       r.cells[i].bgColor=oldc[i];
       }
      }
     }
     //
     // Jump to a page
     //
     function jump() {
      parent.location = document.links.url.options[document.links.url.selectedIndex].value;
     }
     //
    // End -->
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=""x.oSrc;
    }
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=""a[i];}}
    }
    function MM_findObj(n, d) { //v4.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && document.getElementById) x=document.getElementById(n); return x;
    }
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) 
    x.oSrc=""x.src; x.src=""a[i+2];}
    }
    //-->
    </SCRIPT>
    Add your web design / hosting companies to my directory - Web Hosting Directory
    Want to join our panel of experts? - Hosting Forums ( top right of forums -expert drop down box for more info ).

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following is your js combined. I've removed all html script and comment tags. Save this as 'page.js' (or whatever you want to name it).

    Code:
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    }
    function formHandler(form){
      var URL = document.form.site.options[document.form.site.selectedIndex].value;
      window.location.href = URL;
    }
    function expandDiv(tlll) {
      what = eval(tlll + "_menu" );
      if (what.style.display == "none" ) {
        what.style.display = "";
      } 
      else
       what.style.display = "none";
    }
    var oldc = new Array;
    function cCell(r,m){
      if(!document.all) return;
      if(m){
       for(i=0;i<r.cells.length;i++){
       oldc[i]=r.cells[i].bgColor;
       r.cells[i].bgColor='D3D3D3';
       }
      }else{
       for(i=0;i<r.cells.length;i++){
       r.cells[i].bgColor=oldc[i];
       }
      }
     }
     //
     // Jump to a page
     //
     function jump() {
      parent.location = document.links.url.options[document.links.url.selectedIndex].value;
     }
     //
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=""x.oSrc;
    }
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
      var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
      if (a[i].indexOf("#" )!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=""a[i];}}
    }
    function MM_findObj(n, d) { //v4.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?" ))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && document.getElementById) x=document.getElementById(n); return x;
    }
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
      if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) 
      x.oSrc=""x.src; x.src=""a[i+2];}
    }
    You could also combine the CSS into one file ('page.css').
    Code:
    .table {
      border-right: 2px dashed #333399;
      margin: 0px auto 0px auto;
    }
    body { SCROLLBAR-FACE-COLOR: 333399; SCROLLBAR-HIGHLIGHT-COLOR: FFFFFF; SCROLLBAR-SHADOW-COLOR: FFFFFF;  SCROLLBAR-3DLIGHT-COLOR: 000000; SCROLLBAR-ARROW-COLOR: FFFFFF; SCROLLBAR-TRACK-COLOR: CCCCCC; SCROLLBAR-DARKSHADOW-COLOR: 000000 }
    .two { background: #000000; color: #FFFFFF; font-family: Arial,Helvetica,Verdana; font-size: 10pt; font-weight: bold; }
    .form {TD [ (font-family: Verdana; font-size: 11pt; color: #333399; )
    INPUT, SELECT, TEXTAREA { font-family: Verdana; font-size: 11pt; color: #333399; border-top: 1 solid black; border-left: 1 solid black; border-bottom: 1 solid black; border-right: 1 solid black; background-color: white ]}
    .submit  { color: white; font-weight: bold; font-size: 11px; font-family:arial,geneva,helvetica; background-color: #37379C; border-style: solid; border-bottom:1px solid #9E9EFE;	border-right:1px solid #9E9EFE;border-top:1px solid #9E9EFE;border-left:1px solid #9E9EFE; cursor: hand }
    .submit_l  { color: white; width: 120px; font-weight: bold; font-size: 11px; font-family:arial,geneva,helvetica; background-color: #CC0000; border-style: solid; border-bottom:1px solid #000000;	border-right:1px solid #000000;border-top:1px solid #000000;border-left:1px solid #000000; cursor: hand }
    .dropdown { font-family:arial,geneva,helvetica; width: 120px; font-size: 11px; color:black;}
    Now your html file will look like...
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Web Hosting Directory - web site hosting and design companies</title>
    <meta name="description" content="...">
    <meta name="keywords" content="...">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel=stylesheet type="text/css" href="Demo1.css">
    <link rel=stylesheet type="text/css" href="page.css">
    <script type="text/javascript" src='page.js'></script>
    </head>
    
    <body>
    
    ...
    
    </body>
    </html>

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    London, UK
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For some reason i get a error now. Are you sure the two javascripts are integrated properly?
    Add your web design / hosting companies to my directory - Web Hosting Directory
    Want to join our panel of experts? - Hosting Forums ( top right of forums -expert drop down box for more info ).

  6. #6
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    London, UK
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its ok, i worked it out. I had one javascript already being called twice. Thanks for helping me with this, i really appreciate it.

    Add your web design / hosting companies to my directory - Web Hosting Directory
    Want to join our panel of experts? - Hosting Forums ( top right of forums -expert drop down box for more info ).


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
  •