SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,623
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    Question about multiple script blocks

    Hello,

    Whenever I can i of course combine multiple script tags into one. Is there any way to do that (aside from docwrite) if each one needs a wrapping div?

    <div>
    <script type="text/javascript">

    </script>
    </div>
    <div>
    <script type="text/javascript">

    </script>
    </div>
    <div>
    <script type="text/javascript">

    </script>
    </div>

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Why would you need a div for a script tag? They aren't displayable......
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,623
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Two reasons. I floating 2 left. And to give it a height while JS is on so it doesn't load like **** like sitepoint. The space is preserved.

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Again, scripts are not displayed.

    If you need the space, then fine, handle that through css. But wrapping scripts in divs don't gain you anything.....
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,600
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Just put all the script tags just before the </body> tag. If the scripts are so antiquated that they don't work when placed there then either update the script or replace it with a more modern one that works properly with modern browsers - the scripts that need to go earlier in the page are written for Netscape 4 and earlier.

    If what the scripts are outputting need to be in div tags then place the div tags by themselves in the page where they need to go and give each an id that allows the associated JavaScript to reference it. The div tag can then be styled either from CSS or from the JavaScript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,623
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    They are adsense blocks. So they also have a large external script with each. Same script (link at least) but I can't just say it once - stupid. So they load exactly where they are placed. I can probably get away without the wrapping divs. just means I have to make sense of the convoluted code and find the correct id to target.

    I need to test this. But the adsense JS is very slow to load. So I thought I would wrap with the div to preserve the space to keep things from moving around once it loads.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,600
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Adsense uses primitive JavaScript using document.write and iframes (where a script intended for browsers more modern than the Netscape 4 browser that Google continue to write JavaScript for would use innerHTML and either a div or object tag).

    You can move all the adsense scripts to the bottom of the page but it means adding even more JavaScript to the page that parses the antiquated document.write statements and converts them into JavaScript more suited to the middle ages (far more recent than the pre-dinosaur version that Google produce). See http://www.felgall.com/jstip148.htm for how to rewrite the adsense calls to use postscribe to allow the script to be placed at the bottom of the page where JavaScript belongs.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •