how to print the contents of a hidden iframe?

2019-05-27 03:28发布

问题:

i want to print a page which i put in an iframe but dont want the contents to be displayed in the webpage , but the print button doesnt work when i put the iframe to display='none'

what i did:- i set the iframe style='none'

"name="frame1" >
<input type="button" onclick="frames['frame1'].print()" value="print!">

how can i print the contents of iframe without displaying it on the webpage or say by keeping the ifram hidden

would really appreciate any help.....

回答1:

You do a print css file, and within that file you do not have the display: none style.

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

Here's a link to media types, thanks to Dror.



回答2:

Instead of display: none, you could try visibility: hidden and setting the width and height to 1px each.