【问题标题】:How to run script after click, but before redirect如何在单击后但在重定向之前运行脚本
【发布时间】:2020-08-18 12:07:12
【问题描述】:

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

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

我该怎么做?

【问题讨论】:

标签: javascript analytics


【解决方案1】:

参考:open-link-in-new-tab-or-window

这可能对你有用:

$('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>

代码基于本文接受的答案示例: Highlight target

【讨论】:

  • 我可以在同一个窗口中执行此操作吗?
  • @Vladimir 同一个窗口是什么意思?您想知道是否可以在同一窗口中使用“单击”功能,还是要链接到窗口的某个部分?
  • @Vladimir 是的,您可以在同一个窗口中进行操作。我已根据您在评论中的问题编辑了答案。
  • @Vladimir 我的回答是否正确或至少对您有帮助?
猜你喜欢
  • 1970-01-01
  • 2018-04-02
  • 2020-03-25
  • 2011-06-05
  • 1970-01-01
  • 2018-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多