English 中文(简体)
在新标签/窗口中打开时单击() 事件
原标题:.click() event when Open in new tab/window

当我在 标签上使用 . kick () 时,该事件只有在我点击元素时才有效。 否则,如果用户右键点击 & gt; 在新窗口中打开或在新标签中打开, 它不会触发 点击 事件 。

因此,我的问题是... 当用户右键单击 & gt; 在新标签/窗口打开时, 我如何触发 < code> kick () 事件?

以下是 HTML :

<a href="url">Click Me</a>

这里是Js:

$("a").click(function(){
  alert( You clicked me! );
});
最佳回答

您可以尝试这个代码, 但记住更改 UI 不是一种好的想法:

var addEvent = (document.addEventListener) ?
    function(target,event,fn){
        if(target) return target.addEventListener(event,fn,false);
    }:
    function(target,event,fn){
        if(target) return target.attachEvent(( on  + event),fn);
    },
allLinks = document.links || document.getElementsByTagName( a );
for(var i=0;i<allLinks.length;i++)
    addEvent(allLinks[i], mouseup ,function(e){
        var e = e  || event;
        if(e.which===3){
            alert( Open in new tab/window );
            e.preventDefault();
            return false;
        }
    });
问题回答

暂无回答




相关问题
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.

热门标签