Вы должны разрешить браузеру выполнять синтаксический анализ, например, так:
var doc = document.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = '<body onload="alert(1)"></body>'; // your string here
Затем получите атрибуты on*
, используя методы DOM:
var attributes = Array.prototype.slice.call(doc.body.attributes);
for (var i = 0; i < attributes.length; i++) {
if (/^on/.test(attributes[i].name)) {
console.log(attributes[i].name, attributes[i].value);
}
}