确认对话框后显示打印窗口

时间:2019-06-12 11:55:31

标签: jquery ruby-on-rails

在某些情况下,我必须首先显示一个确认对话框,如果用户单击“确定”,它将显示打印窗口,如果用户单击“取消”,则将不显示打印窗口。

a href =“#” class =“ btn btn-sm主浮动右边隐藏打印<%= params [:print_on_load]?” Mandatory_print_invoice“:”“%>” onClick =“ window.print(); “>打印一个

点击打印后,将显示打印窗口。但是我必须先在单击“打印”后显示一个确认对话框,然后它将显示“打印”窗口

3 个答案:

答案 0 :(得分:1)

您应该这样做

document.querySelector('button').onclick = () => {
  if (confirm("Do you want to print?")) {
    window.print();
  }
}
<button>Print</button>

答案 1 :(得分:1)

尝试一下:

     [org.quartz.core.ErrorLogger] (scheduler_QuartzSchedulerThread) An error occured while scanning for the next trigger to fire.: org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.scheduler': java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/jdbc/abc_datasource [See nested exception: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/jdbc/abc_datasource]
     at   
org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:165) [quartz-1.8.4.jar:]
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3760) [quartz-1.8.4.jar:]
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2728) [quartz-1.8.4.jar:]
        at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264) [quartz-1.8.4.jar:]
    Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/jdbc/abc_datasource
        at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:151)
        at org.springframework.scheduling.quartz.LocalDataSourceJobStore$2.getConnection(LocalDataSourceJobStore.java:131) [spring-context-support-3.2.18.RELEASE.jar:3.2.18.RELEASE]
        at org.quartz.utils.DBConnectionManager.getConnection(DBConnectionManager.java:109) [quartz-1.8.4.jar:]
        at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:162) [quartz-1.8.4.jar:]
        ... 3 more
    Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/jdbc/abc_datasource
        at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:421)
        at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:368)
        at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:510)
        at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:143)
        ... 6 more
    Caused by: javax.resource.ResourceException: IJ000658: Unexpected throwable while trying to create a connection: null
        at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:421)
        at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:453)
        at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:425)
        at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:354)
        ... 9 more
    Caused by: javax.resource.ResourceException: Could not create connection
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:356)
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:304)
        at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:834)
        at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:379)
        ... 12 more
    Caused by: com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][3.62.56] A communication error occurred during operations on the connection underlying socket, socket input stream, 
    or socket output stream.  Error location: Reply.fill() - socketInputStream.read (-1).  Message: Software caused connection abort: recv failed. ERRORCODE=-4499, SQLSTATE=08001
        at com.ibm.db2.jcc.am.fd.a(fd.java:319) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.a.a(a.java:461) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.a.a(a.java:456) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.z.b(z.java:209) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.z.c(z.java:268) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.z.c(z.java:381) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.z.v(z.java:1149) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.ab.a(ab.java:45) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.b.n(b.java:1251) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.b.b(b.java:1123) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.b.c(b.java:717) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.b.b(b.java:703) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.b.a(b.java:389) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.t4.b.<init>(b.java:318) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:214) [db2jcc-9.7.4.jar:]
        at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:460) [db2jcc-9.7.4.jar:]
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:328)
        ... 15 more
    Caused by: java.net.SocketException: Software caused connection abort: recv failed
        at java.net.SocketInputStream.socketRead0(Native Method) [rt.jar:1.8.0_171]
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) [rt.jar:1.8.0_171]
        at java.net.SocketInputStream.read(SocketInputStream.java:171) [rt.jar:1.8.0_171]
        at java.net.SocketInputStream.read(SocketInputStream.java:141) [rt.jar:1.8.0_171]
        at com.ibm.db2.jcc.t4.z.b(z.java:199) [db2jcc-9.7.4.jar:]
        ... 28 more
var $dialog_btn = $('#dialog-btn'),
    $print_box = $('#print-box'),
    $print_btn = $('#print-btn');

$dialog_btn.on('click', function(e){
  e.preventDefault();
  $print_box.fadeIn();
});
 
 
$print_btn.on('click', function(e){
  e.preventDefault();
  window.print();
});
#print-box {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 9999;
  background: #f0f0f0;
  box-shadow: 0 0px 5px #000;
  transform: translate(-50%,-50%);
  font-size: 20px;
  font-weight: bold;
  padding: 50px;
}

#print-box a {
  text-decoration: none;
  color: #fff;
  padding: 7px 10px;
  background: red;
}

#dialog-btn {
  color: #fff;
  font-size: 20px;
  text-decoration: none;
  padding: 7px 10px;
  background: red;
}

答案 2 :(得分:1)

尝试此代码。

$(document).on('click','button',function()
{
   if(confirm("Print"))
   {
     window.print();
   }
});