当我点击href链接时要显示广告
我正在使用下面的脚本来显示我的广告。我正在使用onclick来显示我的广告。我尝试以下代码:当我点击href链接时要显示广告
<a href="#" onclick="doalert(this); return false;" >Click here</a>
function doalert(obj) {
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- xxxxxxxxxxxx -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxxxxxxx"
data-ad-slot="xxxxxxxxxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
}
我想检查页面而不点击广告是负载。
要求 - 我点击显示广告链接。否则没有加载广告。
只是改变未成年人的语法,你可以让你的代码的可执行
<a href="www.mysite.com" onclick="return theFunction();">Item</a>
<script type="text/javascript">
function theFunction() {
// return true or false, depending on whether you want to allow the `href` property to follow through or not
}
</script>
的<a>
标签的onclick
和href
属性的默认行为是执行onclick
,然后按照href
只要onclick
没有按” t返回false,取消事件(或事件未被阻止)
将HTML内容直接放入JavaScript函数中将不起作用。你能为此提供解决方案吗? – showdev
你可以把你的html变成javascript var element = document.getElementById(“divID”); ' 'element.innerHTML =“你的HTML这里‘;' –
如果代码是在页面的身体和你想要它写在那里你可以 '使用文件撰写(’你的HTML这里” );' –
我想你需要学习JS,以及如何使用JS插入基本的HTML。 – evolutionxbox
这可能会有所帮助:[用JavaScript动态插入Adsense](http://stackoverflow.com/questions/6197768/dynamic-adsense-insertion-with-javascript) – showdev