Php 如何将Adsense广告(脚本标签)放在javascript标签中?
如何将Adsense广告放入javascript标记中Php 如何将Adsense广告(脚本标签)放在javascript标签中?,php,javascript,Php,Javascript,如何将Adsense广告放入javascript标记中 <script type="text javascript"> var ad = "<script type="text/javascript"><!-- google_ad_client = "ca-pub-12345"; google_ad_slot = "12345"; google_ad_width = 728; googl
<script type="text javascript">
var ad = "<script type="text/javascript"><!--
google_ad_client = "ca-pub-12345";
google_ad_slot = "12345";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>";
</script>
变量ad=”
";
上述方法显然不起作用。但是,它证明了我在努力做什么。有人能想出如何有效地做到这一点吗?谢谢
更新
这仍然给了我一个语法错误
var ad = "<script type='text/javascript'><!--
google_ad_client = 'ca-pub-12345';
/* plastic surgery body large banner */
google_ad_slot = '12345';
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type='text/javascript'
src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
</script>";
varad=”
";
好吧,第一部分是您的出版商身份信息。这只是脚本,所以要么直接输入:
google_ad_client = "ca-pub-12345";
google_ad_slot = "12345";
google_ad_width = 728;
google_ad_height = 90;
。。。或者您可以使用eval:
var ad = [
'google_ad_client = "ca-pub-12345";',
'google_ad_slot = "12345";',
'google_ad_width = 728;',
'google_ad_height = 90;' ].join('');
eval(ad);
document.write()
可用于创建
标记,但请注意:MSIE有一个错误,扫描单词
,因此始终在表达式中分解它:
<script>
document.write('<scr'+ 'ipt type="text/javascript" ');
document.write(' src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
document.write('</scri' + ' ipt>');
</script>
您可能遇到的唯一问题是,由于Ajax调用,您无法执行此操作。如果您正在使用,可以执行以下操作:
$.ajax('//host/my/tag.js', {
dataType: 'text',
success: function(text) {
$('#target-id').html(text);
}
});
jQuery将自动确定如何将脚本标记激活到这些位置,但是这可能不适用于某些富媒体创意。事实上,它没有太多说明。您能详细说明一下为什么需要这样做吗?您只想将其存储在变量中?然后在字符串var ad=“或使用撇号”中转义如下引号。此外,您正在尝试创建嵌套脚本!查看更新。这仍然会给我带来语法错误。此外,它还用于基于URL中哈希的条件广告。您必须从浏览器中“隐藏”
。最简单的方法是
。这不是一个“bug”-HTML解析器绝对没有选择,只能盲目地扫描
结束标记,因为它无法实际解析
块的内容-应该注意的是,它可能是任何东西,不一定是JavaScript。
$.ajax('//host/my/tag.js', {
dataType: 'text',
success: function(text) {
$('#target-id').html(text);
}
});