开发者

How can one identify the currently clicked link with Javascript?

I am using Internet Explorer.

I added a context menu item (through the registry) such that when right clicking on a link in a webpage a custom menu item pops up. Upon selection, this menu item runs some javascript code.

I want to use the url of the link (on which I right click) in the javascript code - how do I access that url?

*Note that this shou开发者_运维百科ld work for any webpage, not only ones which I have control over.

Thanks in advance!


<script language="JavaScript">
  var parentwin = external.menuArguments;
  var doc = parentwin.document;
  var url = doc.URL;

  // ... the rest of your code here ...

See also.

To get the source object, try:

<script language="JavaScript">
  var parentwin = external.menuArguments;
  var srcElement = parentwin.event.srcElement;

  if (srcElement.tagName == "A") {
    var url = srcElement.href;

    // ... the rest of your code here ...
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜