Hi,
Is it possible for me waiting for a user to click a link, and upon clicking the link the link's text would be obtained?
Maybe by using onClick?
Hi,
Is it possible for me waiting for a user to click a link, and upon clicking the link the link's text would be obtained?
Maybe by using onClick?
This is very simple using jQuery:
<script>
$(document).ready(function(){
$("a").click(function(){alert($(this).text());});
});
</script>
Of course, you'll probably want to do something other than alert the text.
If you mean handling the click event for the links in the page that the user is browsing then this is how:
// handle the load event of the window
window.addEventListener("load",Listen,false);
function Listen()
{
gBrowser.addEventListener("DOMContentLoaded",DocumentLoaded,true);
}
// handle the document load event, this is fired whenever a document is loaded in the browser. Then attach an event listener for the click event
function DocumentLoaded(event) {
var doc = event.originalTarget;
doc.addEventListener("click",GetLinkText,true);
}
// handle the click event of the document and check if the clicked element is an anchor element.
function GetLinkText(event) {
if (event.target instanceof HTMLAnchorElement) {
alert(event.target.innerHTML);
}
}