How to display Google Adsense Ads and show or hide them



6,060 visits, 9,547 views



This tutorial hasn't been translated.


This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.


I will demonstrate how to show or hide Google Adsense ads in your layouts


Add your Google Adsense ad code snippet in your index.html

Tip: Place it right before <body> tag.


Copy paste the Javascript code anywhere below jquery script code.

        <script type="text/javascript">
        function loadAd_menu() {
            var w = jQuery(window).width();
            var h = jQuery(window).height();
            var left = (w/2) - (320/2);
            var top = h-80;
            $('#ad').css({'top': top+'px', 'left': left+'px'});
        function loadAd_levels() {
            var w = jQuery(window).width();
            var left = (w/2) - (320/2);
            var top = 60;
            $('#ad').css({'top': top+'px', 'left': left+'px'});
        function hideAd() {
            $('#ad').css({'top': '0px','left':'-999px'});

loadAd_menu is placing the ad 320 by 50 pixels on the bottom of the page in middle then loadAd_levels is placing the ad on the top. loadAd_levels will place the ad block on the top of the page. hideAd will hide the ad. Please rename and edit the values at will.


Now lets look on how we can trigger these javascript functions from Construct 2.

I hope it helps someone :D

Have a good one,


  • Order by
Want to leave a comment? Login or Register an account!
  • Thank you!

    Would this work on C3? is it possible to position the ads?