【问题标题】:Google Maps AdSense Library - Responsive AdsGoogle 地图 AdSense 库 - 自适应广告
【发布时间】:2015-07-13 14:05:14
【问题描述】:

我有一个针对移动设备和台式机的响应式 Web 地图站点。

我使用Google Maps AdSense Library 来投放广告,但它没有任何内置的响应式解决方案来根据屏幕分辨率投放不同的广告单元尺寸。

有没有人想出一个优雅的解决方案来使 AdSense 库具有响应性?至少基于首次加载网站时的浏览器窗口大小。

【问题讨论】:

    标签: javascript google-maps-api-3 responsive-design adsense


    【解决方案1】:

    使用 jQuery 的一个非常简单的解决方案:

    var adFormat = google.maps.adsense.AdFormat.BANNER;
    if ($(window).width() < 480) adFormat = google.maps.adsense.AdFormat.HALF_BANNER;
    
    try { // Needed as AbBlocker will cause site to fail
        var adUnitDiv = document.createElement('div');
        var adUnitOptions = {
            format: adFormat,
            position: google.maps.ControlPosition.BOTTOM_CENTER,
            map: map,
            visible: true,
            publisherId: 'ca-pub-XXXXXXXXXXX'
        }
        var adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
    }
    catch (error) {
        // Do nothing, error probably caused by an ad blocker.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 2016-09-05
      • 2014-10-14
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多