我正在做一个扩展程序,我想要发生的是提醒用户是否在Facebook上点击了特定链接。并且在我的脚本中,每当我点击一个链接时,它总是提示访问gma。在问如何检查特定链接是否已被点击(JS)
$(document).on("click", "a", function() {
//this == the link that was clicked
var href = $(this).attr("href");
if (window.location.protocol == 'https:'){
if(href == "gmanetwork"){
alert("Accessing Gma");
}}
else{
alert("false");
}
});
注意,你所使用的替代相应的操作员''==在评论'//这个==这是链接点击' – guest271314
添加===运算符后,它不再提醒用户 – Babyz
@Babyz'$(this).attr(“href”)'返回完整的URL。你可以使用'String.prototype.indexOf()'或'RegExp.prototype.test()'检查一组特定的字符if(href.indexOf(“gmanetwork”)!== -1)','if (/gmanetwork/.test(href))'或使用完整的URL'if(href ===“https:// path/to/gmanetwork”)' – guest271314