我有一些用于 Firefox 的代码,用于检查页面上的元素是否存在某个事件处理程序,在本例中为 onclick。自从 FF4 出现以来,我一直在获得 NS_ERROR_NOT_AVAILABLE,我猜这与元素周围的 XPCNativeWrapper 有关。这是我使用的代码:
var elem = null;
var elems = doc.getElementsByTagName('td');
var firefoxWindow = window;
for (a = 0; a < elems.length; a++) {
if (((elems[a] != null && elems[a].hasAttributes() == true && elems[a].getAttribute('onclick') != null && elems[a].getAttribute('onclick').toString().match(/Goodbye Wonderful/gim) != null && elems[a].getAttribute('onclick').toString().match(/Goodbye Wonderful/gim).length >= 0) || (elems[a] != null && elems[a].onclick != null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim) != null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim).length >= 0))) elem = elems[a];
}
var found = false;
var window = null;
for (var i = 0; i < firefoxWindow.frames.length; i++) {
if (firefoxWindow.frames[i].toString().toLowerCase().indexOf('object window') > -1) {
window = firefoxWindow.frames[i];
break;
}
}
function recursiveSearch(frames) {
for (var i = 0; i < frames.length; i++) {
var elems = frames[i].document.getElementsByTagName('td');
for (a = 0; a < elems.length; a++) {
if (((elems[a] != null && elems[a].hasAttributes() == true && elems[a].getAttribute('onclick') != null && elems[a].getAttribute('onclick').toString().match(/Goodbye Wonderful/gim) != null && elems[a].getAttribute('onclick').toString().match(/Goodbye Wonderful/gim).length >= 0) || (elems[a] != null && elems[a].onclick != null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim) != null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim).length >= 0))) elem = elems[a];
}
if (elem) {
found = true;
return;
} else {
if (frames[i].frames.length > 0) {
recursiveSearch(frames[i].frames);
}
}
}
}
if (!elem && window.frames.length > 0) {
recursiveSearch(window.frames);
}
if (elem != null) {
print('##Result##' + elem.tagName);
} else {
print('failed');
我为中间的长线道歉,但确保没有空引用确实很好。我无法找到有关对事件所做的更改的任何内容,因为这在 FF 3.6 中运行良好。我发现分配事件是不同的,但没有提到读取事件属性。