【发布时间】:2018-12-05 14:09:24
【问题描述】:
我有一个 Blogger 博客,我想通过使用 JavaScript 为除内部链接和社交链接之外的所有链接制作重定向页面来跟踪外部链接。
我知道该怎么做:
window.onload = function(){
document.getElementById("aLinkId").addEventListener("click", function(e){
e.preventDefault();
// Here we redirect to the wanted page, with the extra parameter, with the original external URL
location.href = "REDIRECT-PAGE-URL?redirect=" + document.getElementById("aLinkId").href;
}); };
但这不适用于博客链接没有 id,我必须为每个链接添加它。
但是对于重定向页面,我被卡住了。
【问题讨论】:
-
博主链接是什么样的?您可以使用比 id 更通用的选择器来获取链接并遍历它们。
-
只是一个没有 id 的链接 'text'