English 中文(简体)
觉醒
原标题:detect click on link in Firefox

如果某一环节被点击,我想在我的灭火中发现。 迄今为止,我增加了一个点击事件听众对窗口的发言。

  window.addEventListener("click", function(event) { handleWindowClick(event); }, false);

  ...

  handleWindowClick : function(event)  {
    if ("event.target is a link") {
      // do something
    }
  };

有些人将活动联系起来。 目标很简单。 然而,在某些联系方面,我取得了一个超文本素帕要素作为事件。 目标。 右边一线被点击或还有其他途径? 如果它这样做的话,我如何能够确保成功测试这一事件。 分类是一种联系?

问题回答

您在主要窗口上添加了一个活动听众,该窗口登记了任何点击。 回答问题的人必须填写在<代码><span>标签上。 你们需要的是:

Why don t you just put the click event listener to anchors (<a>)?

var hrefs = document.getElementsByTagName( a );

for (i = 0; i < hrefs.length; i++) {
    hrefs[i].addEventListener(...)
    ...
}

http://jquery.com/“rel=“nofollow” 学历:

$( a ).click(function () {
    ...
});

I extended the answer of dku.rajkumar to support arbitrary constructs within "A"-tags. I m simply go up the tree until I either find an "A" or I m at the root (so no link clicked in this case). It seems to do the trick. Thanks to all for your help!

 window.addEventListener("click", function(event) { handleWindowClick(event); }, false);
 ...

 isLink : function(element) {
   if(element.tagName ===  A )
     return true;
   else 
     if (element.parentNode) 
       return this.isLink(element.parentNode)
     else
       return false;
 },

 handleWindowClick : function(event) {
   var element = event.target || event.srcElement;
   var isLink = this.isLink(element);
   if (isLink) 
     dump("A link has been clicked.
");
 },




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签