我正在使用wordpress网站,并试图在单击链接时加载图像(跟踪像素)。我有此代码,但似乎未加载。我想念什么吗?在此先感谢您的帮助。
的HTML
<a class="button" target="_blank" title="" href="/rd/credit-check.php" id="ccBtn"><span class="fusion-button-text">GET YOUR FREE CREDIT SCORES NOW!</span></a>
<div id="pixel"></div>
JS
jQuery("#ccBtn").click(function(){
jQuery("#pixel").html("<img src='http://imageurl.com/img.png' alt='itworks' />");
});
这可能是时间问题。浏览器获取链接的速度必须比图像有时间加载的速度快。
我将jQuery更改为以下内容:
jQuery(document).ready(function($){
$('#ccBtn').on('click', function(e){
e.preventDefault(); //stop click
var $this = $(this);
$this.off('click'); //remove this function when click on link
$("#pixel").html("<img src='http://imageurl.com/img.png' alt='itworks' />"); //add image
setTimeout(function(){$this.trigger('click')}, 500); //click on this link again.
});
});
这会在像素加载时阻止链接触发半秒钟。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句