[removed] inside javascript code [removed]()

前端 未结 5 829
忘掉有多难
忘掉有多难 2020-12-31 17:53

I got a portion of javascript code embedded in HTML (generated on the server side) that looks like this:

function winWriteMail2(){
  var win = open(\'\',\'wi         


        
5条回答
  •  猫巷女王i
    2020-12-31 18:44

    This code worked for me:

    function winWriteMail2(){
        var win = open('','wininfo', 'width=400,height=300,scrollbars=yes,resizable=yes');
        win.document.open();
        win.document.write('');
        win.document.write('');
        win.document.write('this is the body content');
        win.document.write('');
        win.document.close();
    
        var h = win.document.getElementsByTagName("head")[0];
        var js = win.document.createElement("script");
        js.type = "text/javascript";
        js.src = "js/scriptfile.js";
        h.appendChild(js);
    }
    

    Here is what I needed to change in your code to make it work:

    //From
    var js = document.createElement("script");
    //To
    var js = win.document.createElement("script");
    

    You need to create the script element in the same document that you are appending.

提交回复
热议问题