基本上我想要实现的是当用户点击图片时我想抓住父母的href" a"元素并使用变量将其最终推送到GA TAG,因此我对代码进行了修改。
你可以看一下吗。自定义javascript文件名: - 查找最近的
function() {
return function(target, selector) {
while (!target.matches(selector) && !target.matches('body')) {
target = target.parentElement;
}
return target.matches(selector) ? target : undefined;
}
}
自定义javascript文件名: - Retimgexp
function() {
var el = {{Find closest}}({{Click Element}}, 'a[href^="http"]');
return typeof el !== 'undefined' ? el.id : undefined;
}
基本上这是HTML代码
<div class="card__media-overlapping__media">
<a href="https://capgemini.aws.hmn.md/experts/it-strategy-and-transformation/yvette-zzauer/">
<img src="https://eu-west-1.tchyn.io/capgemini-dev/uploads/2017/07/yvette_zzauer.jpg?resize=324,197" alt="Yvette Zzauer">
</a>
</div>
答案 0 :(得分:0)
现在正在工作
我正在引用错误的ID应引用“href”。它现在正在工作。
function() {
var el = {{Find closest}}({{Click Element}}, 'a[href^="http"]');
return typeof el !== 'undefined' ? el.href : undefined;
}
答案 1 :(得分:0)
{{Click Element}}.parentNode.getAttribute("href");