简体   繁体   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>

Above works but I want to print first, then have a short delay and then send the user to the specified page. 上面的作品,但我想先打印,然后稍作延迟,然后将用户发送到指定的页面。

I tried this without success: 我尝试了一下但没有成功:

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

this code requires jquery http://jquery.com/ 此代码需要jquery http://jquery.com/

Please note that setTimeout() is in milliseconds, and a delay of 100 ms will not be noticeable by the user. 请注意,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>

Try this code, this is the same code you have used, i have just edited it 试试这个代码,这是您使用过的相同代码,我刚刚对其进行了编辑

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

this is worked for me. 这对我有用。

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

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