• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

JS code in HTML widgets causing sidebars to not load

Scheduled Pinned Locked Moved NodeBB Development
10 Posts 2 Posters 2.9k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    finid
    wrote on last edited by
    #1

    I had a couple of display ad codes (Google AdSense and another) in HTML widgets and noticed that the sidebars were not loading or loading long after the main content are (home and category pages) have loaded. Didn't know why until I deleted the HTML widgets.

    Not the sidebars load as expected.

    The other part of the ads were not showing in the sidebars.

    So that looks like 2 issues.

    • JS code in HTML widgets affecting the loading of the sidebars

    • JS code not workig in HTML widgets.

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #2

    What code did you put into the sidebar? If one widget crashes then I could see the others going down with them as well

    F 1 Reply Last reply
    0
  • F Offline
    F Offline
    finid
    replied to psychobunny on last edited by finid
    #3

    @psychobunny

    Here's a real sample:

     <script type="text/javascript"><!--
    google_ad_client = "ca-pub-8440766493813069";
    /* 300x250 Post Left July 1 2012 */
    google_ad_slot = "9205608781";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    

    That, btw, is the script for a Google Adsense ad. It's never rendered.

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by psychobunny
    #4

    Let me know if this works for you:

    <div id="adsense-container"></div>
    <script type="text/javascript">
    document.write = function(str) { console.log(str); $('#adsense-container').html(str) };
    </script>
    
    <script type="text/javascript"><!--
    google_ad_client = "ca-pub-xxx";
    google_ad_slot = "xx";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    

    I couldn't test it because I don't think you gave me the right ad ID's and such. BTW, there is a new adsense plugin by @dove which should be a lot more flexible than this widget

    F 1 Reply Last reply
    0
  • F Offline
    F Offline
    finid
    replied to psychobunny on last edited by
    #5

    @psychobunny

    Ok, I just updated the previous post with the complete Google ad code. See if ti works for you.

    About @dove's GA code, it works in-post and for the footer and header area, not in the sidebars. Bu even at that, it's still a little bit buggy.

    I'll test the code you provided.

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #6

    yup, worked on my end. here's the final:

    <div id="adsense-container"></div>
    <script type="text/javascript">
    document.write = function(str) { console.log(str); $('#adsense-container').html(str) };
    </script>
    
    
    <script type="text/javascript"><!--
    google_ad_client = "ca-pub-8440766493813069";
    /* 300x250 Post Left July 1 2012 */
    google_ad_slot = "9205608781";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    

    This will only work for one adsense snippet per page. If you want more I can always tweak it around for you

    F 1 Reply Last reply
    0
  • F Offline
    F Offline
    finid
    replied to psychobunny on last edited by finid
    #7

    @psychobunny

    Thanks. Since I use other display ad providers other than Google, it'd be better to have something that's ad provider agnostic and that will work if more than one such widgets are used. I expect to have 3 of those in the sidebar.

    I'm only using Google code as an example, but don't intend to run Google ads on the sidebar.

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #8
    <script type="text/javascript">
    document.write = function(str) { 
    	document.adcounter = document.adcounter ? (document.adcounter + 1) : 0
    	$('#ad-container-' + document.adcounter).html(str)
    };
    </script>
    
    <div id="ad-container-0"></div>
    
    <script type="text/javascript"><!--
    google_ad_client = "ca-pub-8440766493813069";
    /* 300x250 Post Left July 1 2012 */
    google_ad_slot = "9205608781";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    

    For each advertisement widget on the page, increase the id by 1:

    <div id="ad-container-0"></div>
    ...
    <div id="ad-container-1"></div>
    ... etc
    

    Let me know if this does the trick and maybe I'll publish it as a gist for anybody else who runs into the same issue

    F 2 Replies Last reply
    0
  • F Offline
    F Offline
    finid
    replied to psychobunny on last edited by
    #9

    @psychobunny

    Something's not kosher, but I'll wait until I'm running the latest code before comment further on this.

    1 Reply Last reply
    0
  • F Offline
    F Offline
    finid
    replied to psychobunny on last edited by
    #10

    @psychobunny

    Ok, the Google ad will not show on the home page or category page, only on topic pages. Scripts from another ad provider does not work and the side will not load. The HTML widget, me thinks, should be able to render any HTML/JS script.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development