1
There is the possibility of knowing which element in the HTML is responsible for the error causing action in Javascript?
code:
<button onclick="a(this);">GO!</button>
<script>
window.onerror = function(message, source, lineno, colno, error) {
console.log(error.stack); // event.target = window
}
</script>
Exit:
Referenceerror: a is not defined
At Htmlbuttonelement.onclick (onerror.html:1)
In this reference "Htmlbuttonelement.onclick" says that it is a button and that it was in the onclick event, but at the same time it says nothing, I am not able to select this element somehow, or will be that way, using the stack
is not possible? Would have another way to "arrive" in this element?
var domID = "HTMLButtonElement".id;
addObjLog(document.querySelector(domID)); //exemplo de uso
ReferenceError: a is not defined
- Here is saying that the functiona
is not defined, that is, it does not exist in the context you are calling it.– Pedro Camara Junior
@Pedrocamarajunior is not quite that, the error is purposeful, to trigger the event of onerror, the idea would be to know that it was the button that made the error through this event
– Oracio
Ah, okay. I get it. =/
– Pedro Camara Junior