Google chrome extension 如何在chrome扩展中添加adsense代码?
我想在chrome扩展中添加adsense代码(manifest\u版本:2) 我有一个popup.html页面,其中有一个专门的广告块:Google chrome extension 如何在chrome扩展中添加adsense代码?,google-chrome-extension,adsense,Google Chrome Extension,Adsense,我想在chrome扩展中添加adsense代码(manifest\u版本:2) 我有一个popup.html页面,其中有一个专门的广告块: <div id="adblock"> <script type="text/javascript"><!--google_ad_client = "ca-pub-xxxxxx";/* Getfiles Chrome Extn Banner 468x60 */google_ad_slot = "xxxxxx
<div id="adblock">
<script type="text/javascript"><!--google_ad_client = "ca-pub-xxxxxx";/* Getfiles Chrome Extn Banner 468x60 */google_ad_slot = "xxxxxx"; google_ad_width = 468;google_ad_height = 60;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>
这是因为新的内容安全策略禁止内联javascript
为了克服这个问题,我尝试在popup.js文件中创建代码
document.addEventListener('DOMSubtreeModified', function() {
var x = chrome.extension.getViews({type:"popup"});
rowOutput='<script type="text/javascript"><!--google_ad_client = "ca-pub-xxxx";/* Getfiles Chrome Extn Banner 468x60 */google_ad_slot = "xxxx"; google_ad_width = 468;google_ad_height = 60;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
if (x.length>0){
x[0].document.getElementById('adblock').innerHTML=rowOutput;
}
}, true);
document.addEventListener('domsubtremodified',function(){
var x=chrome.extension.getViews({type:“popup”});
rowOutput='';
如果(x.length>0){
x[0]。document.getElementById('adblock')。innerHTML=rowOutput;
}
},对);
当我重新加载扩展并单击扩展图标时,浏览器将挂起,弹出窗口不会打开。在清单中添加此项
"content_security_policy": "object-src 'unsafe-eval'; script-src 'unsafe-eval' https://pagead2.googlesyndication.com; connect-src *"
然后仅添加“s”
改变
与
在清单中添加此
"content_security_policy": "object-src 'unsafe-eval'; script-src 'unsafe-eval' https://pagead2.googlesyndication.com; connect-src *"
然后仅添加“s”
改变
与