How to write JavaScript to a separate window?

前端 未结 2 1611
自闭症患者
自闭症患者 2020-12-21 16:51

I have opened a new window with JavaScript:

var newwin = window.open(\'\',\'preview\',\'width=600,height=500\');

Now I want to write some J

相关标签:
2条回答
  • 2020-12-21 17:18

    Your code running ok on my Firefox 3.7, Opera 10, and IE6, but you could try different approach by using DOM functions.

    var newwin = window.open('','preview','width=600,height=500');
    
    function sayHi(){
        alert('Hi!');
    }
    
    var script = newwin.document.createElement("script");
    script.type = "text/javascript";
    script.textContent = "(" + sayHi + ")();";
    newwin.document.body.appendChild(script);
    

    If its not working, you should double check popup blockers or javascript blockers on your browser.

    0 讨论(0)
  • 2020-12-21 17:20
    function SetContent() 
    { 
        $(newwin).find('#content').html('New Text'); 
    } 
    
    0 讨论(0)
提交回复
热议问题