2013-02-12 49 views
0

有人可以幫助我瞭解下面的鏈接的過程中,內部的onClick特別是部分:什麼是this.href.substr(23)爲GA事件處理過程做的事情?

<a href="http://www.example.com/files/download/files.php?file=my_file.doc" onClick="_gaq.push(['_trackEvent', 'Downloads', 'DOC', this.href.substr(23)]); fn12_reminder(this,''); return false;" rel="nofollow"> 

我明白,這是簡單的GA甚至跟蹤的過程,但我不明白的是最後一部分this.href.substr(23)我不能弄清楚在整個過程中實際做了什麼?

在頭加載JS腳本是下列性質(我張貼在充分,讓有經驗的人可以發現一個連接,如果存在的話):

var functions = true; 
function fn12_custom_display_notice(theNotice,theClass){ 
    if(theClass!=''){ 
     jQuery("#user-notice").removeClass(); 
     jQuery("#user-notice").addClass(theClass); 
     } 
     jQuery("#user-notice").html(theNotice).animate({width:'toggle'},250).delay(3000).animate({width:'toggle'},250); 
     } 
function fn12_custom_display_reminder(theHTML,theDownloadLink){if(typeof jQuery.ui!='undefined'){$("#dialog").attr("title","Please help spread the word").html(theHTML);$("#dialog").dialog({modal:true,width:375,buttons:{"Continue to Download":function(){$(this).dialog("close");window.location=theDownloadLink;}}});}else{window.location=theDownloadLink;}} 
function fn12_custom_reminder(aelem,topic){theLink=$(aelem).attr("href");$.ajax({type:"POST",url:"/db/ajax.php",data:"action=reminder&thepath="+theLink+"&topic="+topic,dataType:"json",error:function(){window.location=theLink;},success:function(msg){if(msg.status==1)fn12_custom_display_reminder(msg.html,theLink);else{fn12_custom_display_notice(msg.message,"error");}}});} 
function fn12_custom_gplus_callback(theObject){if(theObject.state=='on'){fn12_custom_display_notice("Big thanks!!!",'success');}} 

/* jquery_cookie.js Copyright (c) 2006 Klaus Hartl (stilbuero.de), Dual licensed under the MIT and GPL licenses */ 
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'||(name&&typeof name!='string')){if(typeof name=='string'){options=options||{};if(value===null){value='';options.expires=-1;} 
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;} 
expires='; expires='+date.toUTCString();} 
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=name+'='+encodeURIComponent(value)+expires+path+domain+secure;}else{for(var n in name){jQuery.cookie(n,name[n],value||options);}}}else{var returnValue={};if(document.cookie){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(!name){var nameLength=cookie.indexOf('=');returnValue[cookie.substr(0,nameLength)]=decodeURIComponent(cookie.substr(nameLength+1));}else if(cookie.substr(0,name.length+1)==(name+'=')){returnValue=decodeURIComponent(cookie.substr(name.length+1));break;}}} 
return returnValue;}}; 

任何幫助是高度appriciated

回答

1

在您的示例中,this.href.substr(23)等於files/download/files.php?file=my_file.doc,它只是與a元素關聯的網址。

  • this指當前對象,a元素。
  • href引用元素的屬性。
  • substr(23)將從第23個字符開始的子字符串去掉協議和域名。
+0

感謝您的快速響應。接下來的問題是,我發佈的js腳本與它有什麼關係? – AlexB 2013-02-12 14:08:06

+0

發帖之前,我還沒有看過你的完整答案,所以現在它清晰可見。 – AlexB 2013-02-12 14:11:19

相關問題