尝试过多种方法,但仍然无法使用Google广告进行渲染.目的是响应性地根据窗口宽度放置广告.但我甚至无法放置一个广告.
这是我能想到的最可靠的方法:
/* templates.html */
<head>
<script type="text/javascript">
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script type="text/javascript" src="http://www.googletagservices.com/tag/js/gpt.js"> </script>
</head>
<body>
<div class="container">
{{> page}}
</div>
</body>
<template name="page">
<div class="page_ad"></div>
</template>
/* client.js */
Template.page.rendered = function(){
googletag.cmd.push(function() {
googletag.defineSlot('LEADERBOARD', [728, 90], 'AD-CODE-ID').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
$('.page_ad').html("<div id='AD-CODE-ID' style='width:728px; height:90px;'>");
googletag.cmd.push(function() { googletag.display('AD-CODE-ID')});
};
Run Code Online (Sandbox Code Playgroud)
谢谢你的考虑.
meteor ×1