www.webdeveloper.com
Results 1 to 4 of 4

Thread: Is this code ok?

  1. #1
    Join Date
    Oct 2007
    Posts
    4

    Is this code ok?

    I am trying to display Adsense ads conditionally, is there anything wrong with the syntax of this code?

    <script type="text/javascript">
    if (asppg_showGoogleAds)
    {
    document.write("<sc"+"ript type='text/javascript' src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></scr"+"ipt>");
    }
    </script>

    Thanks

  2. #2
    Join Date
    Jan 2009
    Location
    Sao Paulo, Brazil
    Posts
    15
    You try this code:

    Code:
    if (asppg_showGoogleAds) {
    	var sc = document.createElement('script');
    	sc.src = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
    	sc.type = 'text/javascript';
    	document.getElementsByTagName('head')[0].appendChild(sc);
    }

  3. #3
    Join Date
    Oct 2007
    Posts
    4
    Thank you pitiko, I tried it but it does not work

  4. #4
    Join Date
    Jan 2013
    Posts
    4
    There shouldn't be a problem with that javascript, but why are you splitting it up into different substrings?

    Try this, it should do the same thing:

    Code:
    if (asppg_showGoogleAds) {
         var script = "<script type=\"text/javascript\" src='http://pagead2.googlesyndication.com/pagead/show_ads.js'><\/script>";
         document.write(script);
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles