MozillaZine

Link to alternate page when printing

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
SteveBro
 
Posts: 2
Joined: September 26th, 2007, 9:53 am

Post Posted September 26th, 2007, 9:58 am

I am trying to have a different print view then a display view and have put into my <head>:
<link rel="alternate" media="print" href="print.php">
This link works on IE but is not working with Firefox 2.0. Is this capability not support in Firefox or is there something I am missing or a required tag for Firefox?

old SKopischke
Moderator
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted September 26th, 2007, 10:44 am

Moving to Web Development / Standards Evangelism.

jscher2000

User avatar
 
Posts: 10786
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted September 26th, 2007, 1:36 pm

If I recall correctly, Firefox doesn't like CSS when it is served as text/html. Is this file --
Code: Select all
<link rel="alternate" media="print" href="print.php">

-- served with a content-type of text/css? I think in your PHP, toward the beginning of the file, you would need to have something like this to override the web server's default:
Code: Select all
header('Content-type: text/css');

Bethrezen
 
Posts: 405
Joined: September 13th, 2003, 11:56 am

Post Posted September 26th, 2007, 6:49 pm

hi

why not just add a print link to the top of your page that when clicked on takes the user to a printer friendly version of the page ?? that shouldn't be hard to set up

add this to the top of your page

Code: Select all
<a href="index.php?page=print">Print Page</a>


then add this to the head section of your index page

Code: Select all
<?php if ($page == "print"
echo "<link rel='stylesheet' type='text/css' href='print.css'>"; ?>


that simple check will make sure this style sheet is only applied gets applied when the user clicks the print link then all you need do is code print.css such that it overrides any other styling that is applied

either that or you could get a little more complicated and code a switch script that will automatically change what style sheet is applied to a given page based on a few simple checks

here is how i do this on the site i been building

Code: Select all
<head>

<?php include("Switch/style-switcher.php"); ?>

</head>


here is the style sheet switch script

Code: Select all
<?php

// Applied to all pages
if ($page != "")
echo "<link rel='stylesheet' type='text/css' href='Styles/universal-style.css'>
";

// Applied to all pages except these 4
if ($page != "Site-Map"
&& $page != "Internet-Explorer"
&& $page != "Testing-And-Validation-Services"
&& $page != "Proxies-And-Web-Filters")
echo "<link rel='stylesheet' type='text/css' href='Styles/nav.css'>
";

// Applied only to the site map
if ($page == "Site-Map")
echo "<link rel='stylesheet' type='text/css' href='Styles/site-map.css'>
";

// Applied to all pages only when using IE6
if (strstr($_SERVER['HTTP_USER_AGENT'],"MSIE 6") && ($page != ""))
echo "<link rel='stylesheet' type='text/css' href='Styles/ie6-hacks.css'>
";

// Applied to all pages only when using IE7
if (strstr($_SERVER['HTTP_USER_AGENT'],"MSIE 7") && ($page != ""))
echo "<link rel='stylesheet' type='text/css' href='Styles/ie7-hacks.css'>
";

// Applied only to these 4 pages
if ($page == "Internet-Explorer"
|| $page == "Testing-And-Validation-Services"
|| $page == "Proxies-And-Web-Filters"
|| $page == "Site-Map")
echo "<link rel='stylesheet' type='text/css' href='styles/override.css'>
";

// Applied to all pages except these 4 only when using IE6
if (strstr($_SERVER['HTTP_USER_AGENT'],"MSIE 6")
&& ($page != "Site-Map"
&& $page != "Internet-Explorer"
&& $page != "Testing-And-Validation-Services"
&& $page != "Proxies-And-Web-Filters"))
echo "<script type=text/javascript src='Scripts/IE-hover.js'></script>
";

// Applied to all pages only when using Opera
if (strstr($_SERVER['HTTP_USER_AGENT'],"Opera"))
echo "<link rel='stylesheet' type='text/css' href='Styles/Adjust-Opera.css'>
";

?>


hope this helps

jscher2000

User avatar
 
Posts: 10786
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted September 26th, 2007, 7:06 pm

Bethrezen wrote:why not just add a print link to the top of your page that when clicked on takes the user to a printer friendly version of the page ??

Because it isn't necessary and causes another round-trip to the server?

The only argument I see for having special print-formatted pages is that some users might prefer to surf/read that way (usually due to fewer ads!), or a rare few might prefer to print the "screen" version. In general, it makes more sense to have the print style sheet wired into your pages by default.

Here's an example I've been tweaking gradually when I have free time: http://thailand.jeffersonscher.com/dest/KohSurin.asp. For example, the print style sheet hides the navigation and substitutes a more print-friendly serif font.
Last edited by jscher2000 on March 27th, 2013, 10:14 pm, edited 1 time in total.

SteveBro
 
Posts: 2
Joined: September 26th, 2007, 9:53 am

Post Posted September 27th, 2007, 10:54 am

We have a web application and the currently displayed page has a form with many fields on it. When printing, the format will be completely different so styles are not a good alternative for us. We currently have a Print button that opens up another window with the 'print' version of the form and it invokes the print dialog. The problem we have is people's popup blockers. By using "link rel=alternate" this does not require another window and therefore the popup blockers do not come into play. I do have some other ways I can accomplish my goals but the rel=alternate was an easy solution on IE so I thought I would see if FF supported it.

jscher2000

User avatar
 
Posts: 10786
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted September 27th, 2007, 1:18 pm

SteveBro wrote:By using "link rel=alternate" this does not require another window and therefore the popup blockers do not come into play. I do have some other ways I can accomplish my goals but the rel=alternate was an easy solution on IE so I thought I would see if FF supported it.

You could try rel="alternate stylesheet" per this page: http://www.w3.org/TR/html4/present/styl ... g-external and see whether Firefox likes that better.

Bethrezen
 
Posts: 405
Joined: September 13th, 2003, 11:56 am

Post Posted September 28th, 2007, 9:52 am

Because it isn't necessary and causes another round-trip to the server?


I suppose though it all depends on what it is SteveBro is trying to achieve being that he is using a print link already I don't think my idea of using a style switcher was to far off base

However as he has said that alternative styles aren't a good option due to the print format being completely different perhaps a page switch might be more appropriate

instead of having the printer friendly version of the page open in a new window when the print link is pressed why not have it open in the current one

here is how

first create the switch file

Code: Select all
<?php

echo "<a href='index.php?page=print'>Print Page</a>";

switch ($_GET["page"])

{
  case "print":
  include("location of file/print.php");
  break;
}

?>


and save it as print-switch.php then link to this file like this

Code: Select all
<?php include("location of file/print-switch.php"); ?>


this will display the print link on your page and when clicked will open the print.php file in the current window then all you have to do is to remove the old print link

while this method will still require another call to the server it will open the 'print' version of the form in the current window instead of a new one which eliminates the problems of pop-up blocking and as everything is happening server side it eliminates any browser issues as well and if the user wants the form open in a new windows let them right click and select open in new window

how you would get this to invoke the print dialogue as well I'm not sure I'm still kinda new at this but I'm sure it wouldn't be that difficult

then again as you already have a script for invoking the print dialogue doing it through php is probably unnecessary it would be easer to just link to the script in the print.php file and then modify it appropriately

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 1 guest