Brock Adams给了我以下代码(原始问题:How to add frames to an existing frameset using userscript?),以在现有框架集内创建框架。它适用于Firefox和Greasemonkey,但如何使它与Opera和Violentmonkey一起使用?
var parent = document.getElementById ("mainset");
var child = document.createElement ("frame");
child.style = "background-color: pink;";
parent.appendChild (child);
parent.rows = "30%,30%,30%"
var docRdyInt = null;
var frmCW = child.contentWindow;
if (frmCW) {
//-- Must wait for the new frame to be writable, esp in Firefox.
docRdyInt = setInterval (createFramedPage, 50);
}
else {
alert ("Oopsie! may be a rendering delay in some cases. Try code from console.");
}
function createFramedPage () {
if (frmCW.document.readyState == "complete") {
clearInterval (docRdyInt);
frmCW.document.body.innerHTML = '<p>Hello World!</p>';
}
}
这是Opera显示的错误:
Error running script: frame stuffs TypeError: Cannot convert 'parent' to object Error thrown at line 23, column 0 in <anonymous function>(): parent.appendChild (child);
此外,这可能与我遇到的问题相同吗? Opera frames BUG?
请让我知道我忘了给你什么样的信息。
EDIT 实际上,此代码与上面的代码相同。 (它适用于Firefox,但不适用于Opera。)
var parent = document.getElementById ("mainset");
var child = document.createElement ("frame");
child.style = "background-color: pink;";
parent.appendChild (child);
parent.rows = "30%,30%,30%"
var frmCW = child.contentWindow;
frmCW.document.body.innerHTML = '<p>Hello World!</p>';