Search code examples
javascriptblogger

javascript code not working on blogger blog


I have blogger blog on which i want to show ad network ad code which is given below. I have added this javascript code to html widget but ad is not shown. I tried this same code on my wordpress blog where it is working fine.

    <div class="div11" id="b25f9e9f1760c4f82da91fda4c5669dce"></div>
<script>
    (function(d, w) {
        if (!w.adnet) {
            var s = d.createElement("script");
            s.type = "text/javascript";
            s.src = "//domain.com/loader.js";
            d.getElementsByTagName('head')[0].appendChild(s);
            w.adnet = {host: '//domain.com'};
        }
    })(document, window);
</script>

Solution

  • Check my answer here: Javascript With Quote Causes Missing Argument In Blogger Template

    Probably it's the same issue causing the problem.

    EDIT:

    By Jared Smith's sugestion, here it is the your code with the changes and my reply to question linked above.

    Unless the code is inside an HTML/Javascript widget or inside a post, try like this:

        <script>
    // <![CDATA[
        (function(d, w) {
            if (!w.adnet) {
                var s = d.createElement("script");
                s.type = "text/javascript";
                s.src = "//domain.com/loader.js";
                d.getElementsByTagName('head')[0].appendChild(s);
                w.adnet = {host: '//domain.com'};
            }
        })(document, window);
    // ]]>
        </script>
    

    The reason is that Blogger has a way to mess some javascript coding unless you wrap it inside the CDATA.