2012-04-06 132 views
5

當用戶單擊公司網站上的Facebook按鈕時,我必須觸發雙重照明Floodlight代碼。問題是,整個網站是由umbraco構建的,使用諸如「andthis」之類的小部件,這使得添加功能標籤變得困難。使用Onclick事件處理程序觸發Doubleclick Floodlight

我打算在下面使用這段代碼,所以當用戶點擊包含「共享到社交媒體」按鈕的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> 

回答

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> 
+0

如果我這樣做,它不會激發可言,但有我設置是否正確? $(「#buttonsContainer」)。append('click',function(){ var axel = Math.random()+「」; var a = axel * 10000000000000; document.write('