开发者

how to print another page(or file) when user click browser's print button?

开发者 https://www.devze.com 2023-03-13 01:00 出处:网络
In my web application there is a page such as /article/id. I already add a \"print\" link on this page, so when user click print link he will be linked to a print friendly page called /article-print/i

In my web application there is a page such as /article/id. I already add a "print" link on this page, so when user click print link he will be linked to a print friendly page called /article-print/id. The print friendly page use a little different content and totally different css.

This works fine.

But when a user view /article/id web page and he click the browser's print button (file/print or ctrl+P) instead of my print link, the printer will print /article/id page. This is not what I want.

Is there something I can do to make clicking browser's print button redirected to other page just like /article-print/id?

I know a similar method which is adding a

<link rel="stylesheet" type"text/css" href="print.css" media="print">

into /article/id page. So when browser's print button is clicked, the browse开发者_运维问答r will use print.css to render the print page.

Also this is not what I want. I think since I have already had a print friendly page /article-print/id, can I just redirect print button to it?

Thanks.


You cannot redirect or redefine the browser's print button. That would be a security hole, if you could.

You can use print CSS (the best way) or you can offer your own print button and hope that the user decides to use it (she won't always).

0

精彩评论

暂无评论...
验证码 换一张
取 消