2012-10-17 34 views
0
<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> 
+0

您在使用報價時遇到了一些錯誤,請在 – pkachhia

回答

0

試試這個代碼,這是你已經使用了相同的代碼,我剛纔編輯它

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

,這是爲我工作。

+0

這個很好用,謝謝! – Therese

+0

很高興爲您效勞 – pkachhia

0

這個代碼需要jQuery的http://jquery.com/

請注意setTimeout()還是以毫秒爲單位,而100毫秒的延遲不會被用戶察覺。

<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> 
+0

以下查看我的答案。因此,如果不使用函數並插入腳本標記,就沒有辦法做到這一點?我受限於cms,我可以在頁面中間添加一個HML模塊(我對「真實」代碼沒有訪問權限),但是我不認爲在中間添加了腳本標記頁面將是這樣做的正確方法。 – Therese

+0

是的,看到我的回答 – pkachhia

+0

我相信這也會起作用,但是在不同的情況下,我可以真正訪問所有文件並自由地操縱代碼。 – Therese

相關問題