如何在点击后,但在重定向前运行脚本?

问题描述 投票:0回答:1

请帮助。我有一个登陆页面,在正文中直接链接到我的商店。我想在iframe中使用分析脚本运行特定的链接,只收集点击链接的用户的统计数据。

<a href="www.myshop.com">link</a>

如何才能做到这一点?

javascript analytics
1个回答
0
投票

参考资料。在新标签或窗口中打开链接。

这个可以为你所用。

$('a').click(function(e){
    e.preventDefault();
    var href = this.href;       
    console.log('go to the other page or highlight on the same page');
    location.href = href;
});
#demo {
width: 75%;
margin: 0 auto;
background-color: #fff;
-webkit-transition: all 1s linear;
}

#demo:target {
background-color: #ffa;
-webkit-transition: all 0.2s linear;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#demo">Link to a demo</a>
<div id="demo">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

代码是基于这个帖子的公认答案的例子。突出目标

© www.soinside.com 2019 - 2024. All rights reserved.