SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Has div loaded.......

    I'm using external JS to build my menu, which controls a division.
    I'm having a problem as the menu gets triggered before the division has been written. Is there a way of checking if the division has been written?
    I only want to show the div after it has been written.
    (I dont want to put the JS after the HTML, or put an onload onto every page)
    Also, is there a way of putting an onLoad in an external JS that doesn't get triggered when the JS has loaded, but when the full document has loaded? I've tried a few methods, but they all switch when the external js it is contained in gets loaded?

    Thanks in advance......
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What have you got against putting an onload= into every page?
    Of course, that's just my opinion. I could be wrong.

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    window.onload = functionPointer;

    is the most common
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    doesn't work, beetle. triggers when externel JS has loaded.
    Mr Brownstone....
    If I can write it once, I don't need to write it 40 times!

    How about the
    "if div exists".......any suggestions?
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, you asked and I answered.

    window.onload is analagous to <body onload="">

    window.onload fires AFTER the window object has fully loaded.

    For more info read here and here, since you don't seem inclined to take my word for it.

    ------------

    Now, you can check for an element's existence easily

    if ( myDiv = document.getElementById( 'divId' ) )
    {
    // div exists and reference stored in myDiv
    }
    else
    {
    // div does not exist
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    it has a different effect in a external js for some reason, and that wasn't a negative reaction, just a short answer.
    Thanks for the other suggestion, I'll give it a try.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  7. #7
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I doesn't have a different effect. Computational time may be having it's way with you. I've been to your site and the computational time is well above average. If your menu page has loaded but your menu is still processing (read: computing) then any onload-triggered script may run to completion before the other (menu) script is 'done' processing.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  8. #8
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I wrote window.onload=alert(); in my external js and the alert gets called before the divisions are in place, as though it does not know what the division is. It triggers before the body of the HTML is placed on the screen.
    The divisions are the last things to be placed, so as soon as the page changes, the mouse is already on the menu, trying to change a division that's not yet known.

    "computational time is well above average" is that slow or fast?

    any suggestions beetle, as you've seen the site?
    It seems to work fine the second time through.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  9. #9
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If I put the onload on the body of the HTML it triggers after the page has loaded, including pics.
    If I put the onload in the external JS, it triggers when the JS has fully loaded, and before it reaches the <body>........

    try it.....
    Code:
    <script src="alert.js" language="javascript" type="text/javascript">
    </script>alert
    <script>alert(1)</script>
    the HTML
    Code:
    window.onLoad=alert()
    the external js
    the alert() triggers before "alert" gets written on the screen, so an onload in an external JS triggers onload of the external JS, not of the whole document.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  10. #10
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Markdidj
    If I can write it once, I don't need to write it 40 times!
    Do you not use a template system, such as ASP, SSI or PHP?
    Of course, that's just my opinion. I could be wrong.

  11. #11
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, just HTML and JS. Server only allows Perl, and I can't get that to work. Besides, I prefer doing things client-side, once it's cached its really fast.
    I will persist..........
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  12. #12
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    window.onload = function() { alert(); }

    instead

    Oh, and I meant on the slow side of average
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  13. #13
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Thats the one.........

    Quote Originally Posted by beetle
    try

    window.onload = function() { alert(); }

    instead

    Oh, and I meant on the slow side of average
    thats the one......thanks.
    whats faster to compute? js or HTML? is it faster to apply 10 pics in HTML, or use a js loop and do it in one sentance?(which is how I do it) I don't know.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  14. #14
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    explain what you mean by 'apply'
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  15. #15
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    my menu....

    Quote Originally Posted by beetle
    explain what you mean by 'apply'
    apply a menu or list of pics.
    faster created in javascript, or faster created in HTML?
    does the browser read and execute html or javascript faster?
    any ideas? take my site.....you say it was slow to calculate the page. would it be faster if I stopped using loops and applied more in HTML?
    I imagine JS would be faster as it is closer to C?????
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  16. #16
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The browser will render native HTML faster than equivalent script-created HTML.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  17. #17
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    no errors........thanks for the help

    Quote Originally Posted by beetle
    The browser will render native HTML faster than equivalent script-created HTML.
    so <img src......> renders faster than document.write('<img src...

    so when I put it in a loop, the javascript writes the HTML, then the browser renders the HTML written by the javascript. It does sound a bit long-winded too!!

    anyway, got rid of those errors on the site, thanks for your help.......
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  18. #18
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Righty-o. And using document.write() the written HTML also has to be serialized into the node tree so it's DOM accessible.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •