Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 browser 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.

like image 901
flanker Avatar asked Jun 13 '11 05:06

flanker


1 Answers

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).

like image 74
Brock Adams Avatar answered Sep 23 '22 18:09

Brock Adams