超链接点击不触发 [英] Hyperlink click is not firing
本文介绍了超链接点击不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要点击使用JavaScript的超链接。我使用这个代码:
I'd like to catch click on hyperlink with JavaScript. I used this code :
for (var i = 0; i < document.links.length; i++) {
document.links[i].onclick = function() {
doSomething();
}
}
在正常超链接 a href =index.html>首页< / a>
一切正常,但链接到pdf文件
On normal hyperlink <a href="index.html">Home</a>
everything works but on link to pdf file
<a href="tmp.pdf">tmp.pdf</a>
action doSomething();
。我的页面重定向到tmp.pdf,而不触发点击事件。我不知道为什么。
action doSomething();
is not called. My page is redirected to tmp.pdf without firing click event. I don't have a idea why.
你能告诉我什么是问题。我想避免jQuery。
Can you advise me what is problem. I'd like to avoid jQuery.
推荐答案
所以,我发现它...某处在javascript文件中我发现这个代码导致我的问题
so, i found it...somewhere in javascript files i found this code that causes my problem
if ( (String($(this).prop('href')).indexOf('.pdf') != -1)) {
evt.stopPropagation();
evt.cancelBubble = true;
感谢
这篇关于超链接点击不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文