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 7 of 7

Thread: From OLD to DOM

  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    From OLD to DOM

    Hi,

    First of all DOM in Dutch means not so clever!

    Secondly, I like to replace a function (mentioned below) to DOM or even W3C standards which basicly does:

    A. download *.js file (with loaded check)
    B. read-out the array it's containing

    Currently i handle things the (very) old way with a hidden iframe:

    1. write html in iframe to download *.js file
    2. Do this a second time to be sure the file is downloaded?!? and handle array
    3. bring array results to function to make string
    4. place string in DIV with documentGetElementById

    Does anyone has a simular function available / can bring me in the right direction?

    Thanks for Your effort,

    Jerome

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts

    Of course I have

    In fact, for the moment I'm just writing a testpage for this kind of action. I've written a couple of bookmarklets that use this mechanism, but they don't work in op7 and saf/konq because of different problems.

    Here's a mechanism for moz/ie5m/iew:

    Code:
    /*\ Bookmarklet href code (IE5.5+Win, IE5Mac, Moz)
     *  by: Liorean <http://liorean.web-graphics.com/> <mailto:liorean@user.bip.net>
     *  url: <http://liorean.web-graphics.com/book...bookmarklet.js>
    \*/
    javascript:// Protocol, will be treated as label if run
    (function(){// Wrap everything in an anonymous function to provide a private scope to the bookmarklet
      var s='http://liorean.web-graphics.com/bookmarklets/bookmarklet.js',// url to load
        t='text/javascript',// script type
        q='\u0022',// greater than sign
        d=document,// space savings
        n=navigator,// dito
        e;// element container
      if(/mac/i.test(n.platform)&&/msie/i.test(n.userAgent)) // if ie5m, do it this way
        (d.createElement('div')).innerHTML='\u003cscript type='+q+t+q+' src='+q+s+q+'\u003e\u003c/script\u003e';// write the script tag to the innerHTML of a div
      else{// otherwise
        (e=d.createElement('script')).src=s;// create script, set source attribute
        e.type=t;// set type attribute
        d.getElementsByTagName('head')[0].appendChild(e)// append it to head element
      }
    })();// Call the anonymous function to execute the bookmarklet
    void('Coded by liorean');// and of course, the author's moral right to be acknowledged for his work
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Hmm, there's currently no way of calling an external script and then performing a function in the current script - the current script will continue to execute while the script is loaded asynchronously. As soon as the script is loaded - but never before the current script is finished - the imported script will run. This means you'll have to move the function calls for handling the script into the script itself, or use setInterval to see if the script is loaded by object detection on whatever you declare in the script.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi liorean,

    Thanks for supporting me with Your code. I think there are some ideas in it which I can sertainly use to build a function.

    To download a *.js file doesn't seem to be the question so much, however on the moment I don't see the link between a *.js file which is just downloaded and reading the array (no function just an array) which the file contains.

    When I understand Your code (very well documented but my knowledge is limited, so say me if I am wrong ) what You achieve is the following (IEwin) simply said:

    You make a <SCRIPT TYPE="text/javascript" SRC="somefile.js"></SCRIPT> and put it in the header of the document, which means the document has the disposal of the *.js file and all it contains.

    Which means that when the file is loaded I can read-out the array with a simple loop.

    Thanks for Your effort,
    Jerome

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Before I forget:

    Q1.
    I will put this script in an external *.js file. Do I need to write the label java script as well?

    Q2.
    Why doesn't it work in IE5.0 / is it possible to make it work in IE5.0 (DOM supported, not?)

    Jerome

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    I don't know - I'd have to fiddle about with the script in that browser a little to determine anything - I believe the reason I wrote ie5.5+w was that I hadn't any install of ie5w to work with at the moment, though, so it might actually work.

    Oh, the "java&#0115;cript:" part is there because this was written to be a bookmarklet href. If you remove all the comments, and remove all unnecessary whitespace (including newlines), you get a bookmarklet href for loading a script.

    If you remove the "java&#0115;cript:" label, you get the same functionality in an embedded or linked script as you get with the "java&#0115;cript:" label on. In a href, however, that label works as a protocol, telling the browser that the link is a javascript link.

    (Oh, and why does these forums split that into "java script:" if you don't escape the characters?)



    As for the link between downloading the file and reading the array, you only have to think of this:
    Code:
    // This is array.js
    var t=[blah,blah,blah,...];
    Code:
    // Your script in the html file
    function doSomethingWithArray(a){
      /*-whatever-*/
    }
    import('array.js'); // start loading file
    doSomethingWithArray(t); // This will throw an error - t isn't declared yet
    The reason for that, is that the array.js file won't be fully loaded by the time you run doSomethingWithArray.

    Instead, you'll have to do it like this:
    Code:
    // This is array.js
    var t=[blah,blah,blah,...];
    doSomethingWithArray(t); // This won't throw an error
    Code:
    // Your script in the html file
    function doSomethingWithArray(a){
      /*-whatever-*/
    }
    import('array.js'); // start loading file

    Hope that helps!
    Last edited by liorean; 03-19-2003 at 10:01 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, liorean,

    Thanks very much and have a great week-end,

    Jerome


  •  

    Posting Permissions

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