为什么js代码在网页中有效但在GreaseMonkey中失败?

时间:2009-11-03 04:05:18

标签: javascript dom greasemonkey

我创建了一个隐藏的框架如下:

var oHiddenFrame = null;
if(oHiddenFrame == null){
oHiddenFrame = document.createElement("iframe");
oHiddenFrame.name = "hiddenFrame";
oHiddenFrame.id = "hiddenFrame";
oHiddenFrame.style.height = "0px";
oHiddenFrame.style.width = "0px";
oHiddenFrame.style.position = "absolute";
oHiddenFrame.style.visbility = "hidden";
document.body.appendChild(oHiddenFrame);
}

然后是听众:

var fnLocation = function(){
frames["hiddenFrame"].location.href = "http://meckmeck.cn";
}

var oButton = document.getElementById("mb_submit");
oButton.addEventListener("click", fnLocation, false);

它在网页中运行良好,但在用 GreaseMonkey

编写时会报告frames.hiddenFrame is undefined

1 个答案:

答案 0 :(得分:1)

你试过吗,

document.getElementById('hiddenFrame').location.href = "http://meckmeck.cn";