Here is my situation. I have some links throughout a website. Some of them look like this:
<a target="_blank" onclick="someFunction()" href="/somFile.pdf">some file</a>
and some look like this:
<a target="_blank" href="/somFile.pdf">some file</a>
All of the links should be calling someFunction() when clicked. The ones that have the call in the onclick attribute are legacy content pages. Newer pages have a jQuery click event attached to them like so:
$(document).ready(function(){
$('a[href$=".pdf"]').click(function() {
someFunction();
});
});
So here's the thing. I can update someFunction(), but I cannot touch the actual links or that jQuery. What I need is to know the href value of the link clicked. I have tried using the following within someFunction() :
var ev = window.event;
origEl = ev.target || ev.srcElement;
console.log(origEl.href);
but this does not work. I also tried console.log(window.event)
and get nothing, says it is undefined. Any idea what I'm missing here, or is it basically impossible without passing a reference to it when the function is called?
edit: to be clear, I cannot as a short or even medium term solution edit the call to someFunction()
in the onclick or in the jQuery code black, so I cannot for instance change them to someFunction(this)
or similar. I'm not sure it is possible to get the href from within someFunction() unless I do that though :(