views:

25

answers:

2

I'd like to be able to right-click on an element on a web page and get the URL of the nearest anchor.

For example, say I'm looking at online docs, and I see a paragraph saying something surprising, then I'd like to be able to right-click on that, choose "copy URL of nearest anchor", then go to my IDE and be able to paste a URL like "http://docs.somelang.org/1.9/manual.htm#section9" into a code comment.

Currently, I have to do "view source" and hunt around for the nearest element.

Anything which does something reasonably close to this in any major browser would suffice, but my ideal answer would be something which can be added to the right-click menu in Chrome.

A: 

You could write a jQuery script that you run on each page, triggering on clicks.

  1. Use jQuerify or similar to activate jQuery on the page.
  2. Then use the console of Chrome, Safari or Firefox to enter your code.
  3. Code could begin along these lines: $('body').live('click', functionThatFindsClosestAnchorElement);

Hope this helps!

sandstrom
A: 

There's a bookmarklet here which does this: https://www.squarefree.com/bookmarklets/webdevel.html#named_anchors

Rich