Page 1 of 1
Open identical page in new window with different CSS
Posted: Wed May 13, 2009 3:19 pm
by CraigC
I would like to create a 'Print' button on a specific page which allows me to open the current page in a new window/tab but the new instance would be formatted differently.
I can successfully open to a new window with <a href="www.same as current site.com" target="_blank".
I have a print stylesheet that I can successfully use if the user tried to print that way.
How can I apply a different stylesheet to the an identical page opened in a new window

Re: Open identical page in new window with different CSS
Posted: Wed May 13, 2009 3:23 pm
by crazycoders
Just by curiosity, the layout is different or just the css? because if that is so, you can simply use:
<style media="print">
</style>
or
<link href="print.css" media="print" />
Re: Open identical page in new window with different CSS
Posted: Wed May 13, 2009 3:29 pm
by CraigC
Just CSS. I do have <link href="print.css" media="print" /> in the header already. but the new window doesn't recognize it as print because it is still in the browser.
I think a simpler explanation is duplicating the "File->Print Preview" functionality in a browser window
Re: Open identical page in new window with different CSS
Posted: Wed May 13, 2009 3:34 pm
by crazycoders
If it's the same page, and you have PHP, send a param to the query string such as:
invoice.php?printpreview=1
and the php file should detect that:
Code: Select all
<html>
<head>
<link rel="stylesheet" href="<?php if(isset($_GET['printpreview'])){ echo 'print.css'; }else{ echo 'normal.css'; } ?>" />
</head>
</html>
If you don't have access to a dynamic language such as PHP, i'd try out javascript, but then, if the user doesn't have javascript, no way of actually doing this.
Re: Open identical page in new window with different CSS
Posted: Wed May 13, 2009 3:36 pm
by CraigC
Excellent! I am developing in PHP and that all makes sense. I'll let you know if I fail, otherwise thank you!