Open identical page in new window with different CSS

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
CraigC
Forum Newbie
Posts: 3
Joined: Wed May 13, 2009 3:00 pm
Location: Cleveland, Ohio

Open identical page in new window with different CSS

Post 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 :?:
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: Open identical page in new window with different CSS

Post 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" />
CraigC
Forum Newbie
Posts: 3
Joined: Wed May 13, 2009 3:00 pm
Location: Cleveland, Ohio

Re: Open identical page in new window with different CSS

Post 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
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: Open identical page in new window with different CSS

Post 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.
CraigC
Forum Newbie
Posts: 3
Joined: Wed May 13, 2009 3:00 pm
Location: Cleveland, Ohio

Re: Open identical page in new window with different CSS

Post by CraigC »

Excellent! I am developing in PHP and that all makes sense. I'll let you know if I fail, otherwise thank you!
Post Reply