我已在网站上安装了以下出站链接跟踪代码,该代码运行良好。
问题是它导致网站上的图像 slider 中的点出现问题(使用 flexslider)。单击这些点时,它们通常会将图像 slider 移动到该幻灯片,但链接跟踪脚本导致页面重新加载并转到“/undefined”(即 www.domain.com/undefined)。
$(function() {
$("a").on('click',function(e) {
var url = $(this).attr("href");
if (e.currentTarget.host != window.location.host) {
_gat._getTrackerByName()._trackEvent("Outbound Links", e.currentTarget.host.replace(':80',''), url, 0);
if (e.metaKey || e.ctrlKey || this.target == "_blank") {
var newtab = true;
}
if (!newtab) {
e.preventDefault();
setTimeout('document.location = "' + url + '"', 100);
}
}
});
});
任何有关如何解决此问题的提示将不胜感激。
提前致谢,
汤姆
最佳答案
您可以过滤选择器结果或检查 href 是否未定义,这似乎是 slider 点的情况,如下所示:
$(function() {
$("a").on('click', function(e) {
var url = $(this).attr("href");
if (url && e.currentTarget.host != window.location.host) {
_gat._getTrackerByName()._trackEvent("Outbound Links", e.currentTarget.host.replace(':80', ''), url, 0);
if (e.metaKey || e.ctrlKey || this.target == "_blank") {
var newtab = true;
}
if (!newtab) {
e.preventDefault();
setTimeout('document.location = "' + url + '"', 100);
}
}
});
});
关于javascript - 出站链接跟踪和 'undefined' 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31945802/