繁体   English   中英

单击打印按钮后如何将用户发送到页面

[英]How to send user to page after clicking print button

<button type="button" onClick="window.location.href='http://mywebsite.com';window.print();return false;">Print</button>

上面的作品,但我想先打印,然后稍作延迟,然后将用户发送到指定的页面。

我尝试了一下但没有成功:

<button type="button" onClick="setTimeout('window.location.href='http://mywebsite.com', 100);window.print();return false;">Print</button>

此代码需要jquery http://jquery.com/

请注意,setTimeout()以毫秒为单位,并且用户不会注意到100 ms的延迟。

<button type="button" id="print_button">Print</button>

<script>
$().ready(function() {
  $(document.getElementById('print_button')).click(function() {
    window.print()

    setTimeout(function() {
       window.location.href = 'http://mywebsite.com'
    }, 5000)

    return false
  })
})
</script>

试试这个代码,这是您使用过的相同代码,我刚刚对其进行了编辑

<button type="button" onClick="setTimeout('window.location.href=\'http://www.google.com\'', 3000);window.print();return false;">Print</button>

这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM