How do I intercept link clicks in document?
It must be cross-platform.
I am looking for something like this:
// content is a div with innerHTML
var content = document.getElementById("ControlPanelContent");
content.addEventListener("click", ContentClick, false);
function ContentClick(event) {
if(event.href == "http://oldurl")
{
event.href = "http://newurl";
}
}
alternatively if you just want to intercept, not change, add an onclick handler. This will get called before navigating to the url:
Note that
document.linksalso containsAREAelements with ahrefattribute – not justAelements.