[Javascript] Loading Problem

liorean liorean at gmail.com
Wed Sep 15 05:35:53 CDT 2004


On Wed, 15 Sep 2004 10:53:07 +0100, Tim Makins <spindrift at oceanfree.net> wrote:
> Today's question:
> My table-viewer uses a number of data-files, such as the above (a shortened
> version). It is stored as 'table_uscount1.js', and will be loaded by
> including the line:
> 
> <script src="gaz/table_uscount1.js"></script>
> 
> at the top of the page that processes it. However, if there are a lot of
> these files, the 'load' gets very big and takes time. Is there a way to only
> load the one I want, when it is asked for ??

Yes there is. However, if you want saf and iem support on the Mac it's
gonna be a long winded one. Also, op didn't support this before
version 7.5. I've not tested doing this on shiira or omniweb, so I
will not even bother with coding for them right now.

function loadScript(address){
    var
        m=/mac/i.test(navigator.platform),
        a=window.ActiveXObject||false,
        x=window.XMLHttpRequest||false,
        s=/apple/i.test(navigator.vendor),
        script;
    // First we do the op7.5/moz/iew solution.
    // No feature detection necessary, all other browsers will just
gracefully fail.
    (script=document.createElement('script')).setAttribute('type','text/javascript');
    script.setAttribute.src=address;
    document.getElementsByTagName('head').item(0).appendChild(script);
    // Okay, that done. How about iem, then?
    if(m&&a)
        document.createElement('div').innerHTML='<script
type="text/javascript" src="'+address+'"><\/script>';
        // You don't even have to insert it into the document!
    // Okay, saf left.
    if(m&&s){
        x.open('GET',address,false);
        x.send(null);
        eval(x.responseText);
    }
}
-- 
David "liorean" Andersson
<uri:http://liorean.web-graphics.com/>



More information about the Javascript mailing list