问题
Brock Adams gave me the code below (original question: How to add frames to an existing frameset using userscript?) to create a frame inside an existing frameset. It works fine with Firefox and Greasemonkey, but how do I make it work with Opera and 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>';
}
}
This the error Opera shows:
Error running script: frame stuffs TypeError: Cannot convert 'parent' to object Error thrown at line 23, column 0 in <anonymous function>(): parent.appendChild (child);
Also, is this perhaps the same problem I'm experiencing? Opera frames BUG?
Please let me know what kind of information I forgot to give you.
EDIT In fact, this code does the same as the above. (It works with Firefox, but not with 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>';
来源:https://stackoverflow.com/questions/25594334/adding-frames-to-an-existing-frameset-using-a-userscript-works-with-firefox-wh