【问题标题】:Firing Doubleclick Floodlight using Onclick Event Handler使用 Onclick 事件处理程序触发 Doubleclick Floodlight
【发布时间】:2012-04-19 21:37:53
【问题描述】:

当用户单击公司网站上的 facebook 按钮时,我必须触发 doublelclick Floodlight 标记。问题是整个网站都是用 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>

【问题讨论】:

    标签: jquery event-handling umbraco double-click onclicklistener


    【解决方案1】:

    当用户单击时,它会重新加载页面,因为您使用的是 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>
    

    【讨论】:

    • 如果我这样做,它根本不会触发,但是我是否正确设置了它? $("#buttonsContainer").append('click', function() { var axel = Math.random() + ""; var a = axel * 10000000000000; document.write('');
    • 据我了解,我只能使用document.write来写我页面的原始内容。页面加载后,我无法使用它来更新页面内容?
    • @Michael King,你是对的,document.write 只能在初始页面加载时使用。在您的示例中,它在用户单击它后触发,这在页面加载后很长时间。
    • @Michael King,我添加了一个示例。希望这更有帮助。当我最初回答这个问题时,它来自我的手机并输入了一个代码示例只是没有意义。 ;)
    猜你喜欢
    • 2016-08-31
    • 2021-08-05
    • 2012-05-27
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 2011-09-07
    • 1970-01-01
    相关资源
    最近更新 更多