Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    how to do external scripting?

    Dear Forum,

    I have a website of quite a few pages which also has a style sheet switcher so the user can select their own customised graphics and layout (css file)

    these css files load in the graphics but only when the call is clicked... even if the page has already been opened for seconds or minutes when the graphics could have been loaded in for an instant switch.

    so i implemented the following code:

    Code:
    <SCRIPT language="javascript">
    
    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];}}
    }
    
    </SCRIPT>
    
    
    <body onLoad="MM_preloadImages('/corporate/heading.png','/creative/heading.png','/earth/heading.png','/under-the-sea/heading.png','/space-and-stars/heading.png','/classical/heading.png','/corporate/document.jpg','/space-and-stars/document.png','/creative/document.jpg','/earth/background.jpg','/under-the-sea/background.jpg','/classical/document.png','/classical/background.jpg','/under-the-sea/document.png','/corporate/home-graphics.png','/earth/content.jpg','/earth/footer.jpg','/earth/home-graphics.png','/under-the-sea/home-graphics.png','/creative/home-graphics.png','/space-and-stars/background.jpg','');">

    it works fantastically - you open the page and as long as it takes to notice where you can click the styles is the same amount of time it takes to have the styles cached for the styles switch immediately and effortlessly.

    however, the site has grown and is now quite a number of pages with the above in each html file. ive just added a "creative 2" style, which has caused the above to need updating........ the maintenance of this code is inefficient to edit each page.



    would someone be able to point or show me how to, in principle:

    Code:
    <body onLoad="MM_preloadImages('/styles-code.js);">
    
    
    
    styles-code.js?? page:
    
    '/corporate/heading.png',
    '/creative/heading.png',
    '/earth/heading.png',
    '/sea/heading.png',
    '/classical/heading.png',
    
    '/corporate/background.jpg',
    '/creative/background.jpg',
    '/earth/background.jpg',
    '/sea/background.jpg',
    '/classical/background.jpg',
    
    etc
    and have 1 page of this code called in by all pages in an easy to see and edit list?


    would really appreciate guidance with this,
    Last edited by secretfire; 09-08-2011 at 01:02 PM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Put this in the HEAD section of all your files:
    Code:
    <script type="text/javascript" src="styles-code.js"></script>
    And write you JS code in that file. Only the code, without the tags <script> and </script>

    See also:
    http://www.pageresource.com/jscript/jxtern.htm
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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