【问题标题】:Java script: open one window print that one and than close it than open one new windowJavascript:打开一个窗口打印那个然后关闭它而不是打开一个新窗口
【发布时间】:2018-05-02 15:38:41
【问题描述】:

我的要求是,我需要打开两个窗口,但第二个窗口必须在第一个窗口打印并关闭之后打开。有可能吗?

但第二个窗口与第一个窗口同时打开。

HTML/JSP 代码 打印

Java 脚本 函数打印(id){

        var data=document.getElementById(id).innerHTML;
        var mywindow = window.open("",'TITLE','left=0,top=0,width=800,height=400,channelmode=no,titlebar=yes,scrollbars=yes,toolbar=no,menubar=no,resizable=yes,copyhistory=no,directories=no,status=yes');
        mywindow.document.write('<html><head><title>TITLE</title>');
        mywindow.document.write("<style type='text/css'>");

        mywindow.document.write(data);
        mywindow.document.write('</body></html>');
        mywindow.document.close(); 
        mywindow.focus(); 
        mywindow.print();
        mywindow.close();
        return true;

}

函数弹出(){ var mysecondWindow = window.open("",'SecUtdOfficialWebsite','width=400,height=400'); }

打印

【问题讨论】:

  • HTML 代码:从哪里触发 java 脚本函数 button type="button" onclick="if(print('test1')){popup();}" >Print跨度>
  • 有afterprint 事件,但没有得到广泛支持。
  • 好的。谢谢!让我看看这是否适合我。

标签: javascript html


【解决方案1】:
$(function(){
  OpenFirstWindow()
})
var mywindow;
var mywindow2;
function OpenFirstWindow(){
 mywindow= window.open('')
          mywindow.document.write('<html><head><title>TITLE</title><body onload="">');
mywindow.document.write("window 1");
        mywindow.document.write('</body></html>');
        mywindow.print();
  mywindow.close()
  OpenSecondWindow();

}


function OpenSecondWindow(){
 mywindow2= window.open('')
          mywindow2.document.write('<html><head><title>TITLE</title><body >');
mywindow2.document.write("window 2");
        mywindow2.document.write('</body></html>');
        mywindow2.document.close(); 
  mywindow2.print();
  mywindow2.close()

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多