How to add script files in child window using javascript?

前端 未结 2 2083
既然无缘
既然无缘 2020-12-21 06:50

How to add script files in child window using javascript?

Consider the following code:

myWindow = window.open(\"\", \"\", \'width=650,height=700,menu         


        
相关标签:
2条回答
  • 2020-12-21 07:04

    Supposing you don't have domain crossing, you may simply do this (using jquery) :

    $(childwindow.document.body).append('<script src="..."></script>');
    

    But a more detailed question might enable more on topic answers.

    0 讨论(0)
  • 2020-12-21 07:05

    Basically:

    var win, doc;
    
    win = window.open('', 'dialog', opts);
    doc = win.document;
    
    doc.write(
        "<html><head>"
        + "<script type='text/javascript' src='path/to/your/script.js'></script>"
        + "<script type='text/javascript'>"
        + "/* this is inline script inserted by JavaScript, below is a function converted to it's string representation */"
        + someFuncInVariable.toString()
        + "</script>"
        + "</head><body>"
        + "</body></html>"
    );
    doc.close();
    
    0 讨论(0)
提交回复
热议问题