Adding frames to an existing frameset using a userscript. Works with Firefox, why not with Opera?

人盡茶涼 提交于 2020-01-07 05:03:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!