使用Onclick事件处理程序触发Doubleclick泛光灯

Mic*_*ing 5 jquery umbraco double-click event-handling onclicklistener

当用户点击公司网站上的facebook按钮时,我必须触发一个双击泛光灯标签.问题是整个网站是由umbraco构建的,其中的小部件如"andthis"用螺栓固定,这使得添加功能标签变得困难.

我计划在下面使用此代码,因此当用户点击包含"分享到社交媒体"按钮的div标签时,它将触发标签,但是在测试中它不仅仅会触发它试图带走用户的标签.我究竟做错了什么?我只是想在用户点击时加载标签,我不想实际离开他们当前所在的页面.

<div id="buttonsContainer">
  <p>Click or double click here.</p>
</div>

<script>
    $("#buttonsContainer").click(function () {

var axel = Math.random() + "";
var a = axel * 10000000000000;
document.write('<iframe src="http://fls.doubleclick.net/activityi;src=36705;type=count134;cat=faceb540;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
});
</script>
Run Code Online (Sandbox Code Playgroud)

Dou*_*low 6

当用户点击时,它正在重新加载页面,因为您正在使用document.write,它会重新打开流以写出页面.你会想要使用$('buttonsContainer').append(''); 将iframe放入buttonsContainer元素中.

例如:

<div id="buttonsContainer">
  <p>Click or double click here.</p>
</div>

<script>
    $('#buttonsContainer').click(function () {
        var axel = Math.random() + '';
        var a = axel * 10000000000000;
        $(this).append('<iframe src="http://fls.doubleclick.net/activityi;src=36705;type=count134;cat=faceb540;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
    });
</script>
Run Code Online (Sandbox Code Playgroud)