出站链接跟踪'undefined'链接
Outbound link tracking and 'undefined' links
我在一个运行良好的网站上安装了以下出站链接跟踪代码。
问题是它会导致网站上的图像滑块中的点出现问题(使用flexslider)。当这些点被点击时,它们通常会将图像滑动条移动到该幻灯片上,但是链接跟踪脚本会导致页面重新加载并转到'/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未定义,这似乎是滑动条的点的情况,如下所示:
$(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函数打开一个新的弹出窗口
- 如何使用jQuery自动打开页面上的所有链接
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- jquery动画可以通过编程链接吗
- 在单击href链接的同时下载文件
- 尽管链接成功并已成功下载,但未找到NPM模块
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 单击页面上的链接后高度发生变化
- 将纯文本URL转换为可单击链接
- python-selenium-点击上升链接
- 一点javascript元编程&可链接的设置器
- ng视图外的链接重定向到ng视图内的页面
- 如何调用“;链接_;在onclick事件上使用Javascript
- 链接所有<a>Meteor
- 如何在Angular中的表的所有单元格中添加链接
- 函数“;链接“;与&&运算符返回undefined
- 出站链接跟踪'undefined'链接
- 检测点击了哪个链接?始终返回undefined.什么'It’他错了
- 为什么我得到这个错误'TypeError undefined不是一个对象…'包括Shopify链接产品选