很明顯,我正在做一些愚蠢的事情。可以通過JavaScript設置mouseover html屬性,但不能在Firefox中爲函數指定mouseover屬性
processTextNodes: function processTextNodes(node) {
node = node || content.document.body; // base node
var children = node.childNodes, i = 0;
while (node = children[i]) {
if (node.nodeType == 3 && node.textContent) { // text node found, replace enclosed text.
if (node.nodeName == "script") continue;
/*node.parentNode.setAttribute("onmouseover", "alert(\"AAA\");");*/
node.parentNode.onmouseover = function(){ alert("AAA") };
node.textContent = aatel.transliterate(node.textContent);
}
if (node.nodeType == 1) {
if (node.title) node.title = aatel.transliterate(node.title);
if (node.alt) node.alt = aatel.transliterate(node.alt);
}
processTextNodes(node);
i++;
}
},
以上是我正在寫的擴展的一種方法。當運行給出上面我得到的錯誤控制檯下面
Error: uncaught exception: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: chrome://aatel/content/overlay.js :: processTextNodes :: line 97" data: no]
如果有任何歧義,行97是:
node.parentNode.onmouseover = function(){ alert("AAA")};
如果我註釋掉行分配功能.onmouseover和取消它上面的setAttribute行註釋,它可以像你期望的那樣工作。這個醜陋的,不透明的例外信息對我幫助不大。我究竟做錯了什麼? Javascript並不是我的強項。
奇怪,我可以發誓,我在網上找到使它的所有例子,就好像是的onmouseover屬性,你可以分配給。我想擴展是奇特的。 – cikkle
現在,我認爲它結束了,我記得直接通過屬性分配是在javascript中添加事件處理程序的傳統方式。它很容易在擴展中發生衝突,所以他們會拒絕它是非常合理的。謝謝。 – cikkle