JavaScript embedding [removed] tags in [removed] not working

后端 未结 3 900
盖世英雄少女心
盖世英雄少女心 2021-01-13 04:39

I\'m not sure what is wrong with my code, but when I try and add actorWin.document.write(\'

3条回答
  •  伪装坚强ぢ
    2021-01-13 05:31

    but when I try and add actorWin.document.write('') everything gets screwed up

    Not sure what's the problem but it may help you

    Writing to a document that has already loaded without calling document.open() will automatically perform a document.open call.

    About document.open call

    If a document exists in the target, this method clears it.

    Read more on MDN.

    Well, whatever your problem is, you may use this approach

    var newWin = window.open('','Win','width=300,height=200,top=100,left=600');
    
    // Then add scripts
    var script1 = document.createElement('script');
    script1.innerHTML = "function someFunc(){  alert('Hello'); }";
    newWin.document.getElementsByTagName('head')[0].appendChild(script1);
    
    var script2 = document.createElement('script');
    script2.src = "http://code.jquery.com/jquery-git2.js";
    newWin.document.getElementsByTagName('head')[0].appendChild(script2);
    

    This should work. An Example here.

提交回复
热议问题