javascript - 如何在单击后但在重定向之前运行脚本
问题描述
请帮忙。我有一个登陆页面,正文中有指向我商店的直接链接。我想在 iframe 中运行带有分析脚本的特定链接,只是为了收集点击链接的用户的统计信息
<a href="www.myshop.com">link</a>
我怎样才能做到这一点?
解决方案
参考: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>
代码基于本文接受答案的示例: 突出显示目标
推荐阅读
- python - 是否可以跨机器共享 virtualenv?
- python - BeautifulSoup RSS 提要提取一个选项卡重排“1”
- nginx - NGINX:强制 nginx 使用所有工作人员进行负载平衡
- node.js - updateMany() 后如何获取所有更新文档的值?
- c++ - char* escape "\" 在 libcurl 的 POSTFIELD 中丢失
- c# - 如何解决此错误“当前不会命中断点。没有为此文档加载任何符号。”
- mit-scratch - 如何将 SB3 文件转换为 EXE
- excel - 使用 excel vba 关闭 Word 应用程序
- r - 在染色体上绘制映射的 SNP?
- android - 多个动画的相同插值器