Discuss: Improving Link Display for Print
by Aaron Gustafson
- Editorial Comments
22 Minor JavaScript Utilities Library bug
While I was looking over the library, I noticed that the regular expression used to remove a class doesn’t take into account that the class name passed in might be part of another class name. For example, if an element has the classes “mycar car”, and you want to remove the car class, it would result in the classes being named “my car” instead of just “mycar”. The fix that I can see would be to change \\s? to \\b in the regular expression.
posted at 08:42 pm on September 20, 2005 by Brian LePore
23 Very cool
This seems to be cool to me, but I am very tired and all that code, while neccessary, currently makes my brainy meats hurt. I understand what it does, and I understand the commented psuedo code near the top of the article, but the code itself melted into an impossible to understand goop right before my eyes. My problem, not yours.
I say all this to cover my butt in case this question is totally stupid due to my current limited understanding of the code. What if you want to index links from multiple site areas in this way? For example, maybe there’s an article, a primary navigation menu with links within the current site, and a seccondary menu with external links to related articles. You want to exclude the nav section but include the other two.
Or what about ways to exlude certain areas? What if the ID containing the article or whatever you want to be indexed contains other children that you don’t want to be indexed, ads or some such?
I know the scripts could be edited (by someone more compitent or at least less sleep deprived than myself) to allow for these sorts of special cases. But how extensible is the script as currently written?
I know these are special cases well beyond the scope you had in mind for this article, which I freely admit is great and don’t mean to knit pick.
And this quasi real time comment preview widget is super cool. Someone should write an article about that.
posted at 12:19 am on September 21, 2005 by Derek Pennycuff
24 Same technique for any page
There is a very cool Greasemonkey user script that will do something similar for any page.
It’s called Annotate Links
posted at 03:55 am on September 21, 2005 by Julien Couvreur
25 Ruining JavaScript?
I really hate being the troll, but the jsUtilities library you reference is pretty dangerous stuff. You’ve extended Object which will effectively break anyone who tries to use for…in in their code.
<ot>Also, it seems strange that you have all your functions written to use apply. Why make things harder than you have to?</ot>
How ‘bout making the unobtrusive JavaScript a bit more unobtrusive?
posted at 04:29 am on September 21, 2005 by David Schontzler
26 Relative links and displaying print style sheets
The reason I didn’t simply filter out relative links (which for many sites would be good enough) is because I had a very good idea about what it was people we’re interested in – the body of the article. Back then I was a bit more disorganised (crufty URLs – ugh!) and would frequently use a fixture of relative and absolute URLs. I think I’ve fixed most of them up now, but even so some of my navigation elements use absolute links (for example my del.icio.us links).
I can’t remember the exact reason why I showed a print view in a new window rather than relying on print preview, but think it came down to be being frustrated by how slow some of the print previews in various browsers were. I also intensly dislike a print link automatically printing something without being able to see it, and hadn’t worked out how to trigger a print preview. As I already had all the cross-browser DOM walking sorted, finding any print stylesheets and adding screen was a breeze.
posted at 05:36 am on September 21, 2005 by Sam Newman
27 Code to make a print style sheet viewable
I dug out the code snippet I used to make my print stylesheets visible. It’s kind of taken out of context – my print reloaded the page using a query string requesting the print view, which in turn changed the stylesheet link:
/*
* Makes all ‘print’ stylesheets ‘screen’ stylesheets as well so you can see how it will print…
* TODO: match on ‘print’ assumes a single media type – need to support a list of media types (with indexof?)
*/
function showPrintStylesheets() {
var links = document.getElementsByTagName(‘link’);
I suppose I really should get around to writing this up too…
posted at 05:52 am on September 21, 2005 by Sam Newman
28 Users
Why would users need to view the printed style? To check that we are not going to waste all the colours on their printer? :P … Is knowledge of printed styles so fleeting in web users that they need to see for sure they are printing a stripped-down ready-for-print version?
Given the number of websites that haven’t got the hang of print stylesheets, and allow sidebars, ad banners and columns wider than a page to be printed, is it any wonder that users are reluctant to just press ‘Print’?
I’ve had a print.css on my website for a long time, but I still get the occasional user suggest that I add a Print-friendly format for each page so that they don’t have to print the blue background – they obviously haven’t found the Print Preview button (and yes, most of them are using IE6 – if they only had v5 I could sympathise).
Those users may be a minority. It may be that most people (i) trust me not to waste their colour ink, (ii) don’t care if I waste their colour ink, or (iii) have found the Preview button. I don’t know, and I don’t know how to find out…
posted at 09:37 am on September 22, 2005 by Stephen Down
29
I just wanted to let everyone know that I will be incorporating a lot of the great ideas/improvements suggested here into the latest revisions of my jsUtilities library and the footnoteLinks script itself (giving credit where it is due, of course). It will probably be a few days before I can get it all together and put it up on my site but I wanted to let you all know that your ideas are great and are not being ignored. If you made a suggestion and would like credit, please email me (aaron [at] easy [dash] designs [dot] net) your name and website (if it isn’t complete here in the discussion) and if your fix makes it in, I will add your info to the comments.
A few quick responses:
- To answer Derek’s concern about excluding certain sections, currently that is not supported, but a
classof “ignore” on any element will effectively exclude it. Also, the script already has the ability to perform its duties on a uniquely identified section of your choosing and (based on my experience) I have not found a need for more. I keep my most important content (which is where I’d want the links pulled from) in adivwith anidof “content.”
- As for David’s concern about my redefining of
Object, I will certainly look into the issue and see if there are remedies (I don’t often usefor...inloops in JavaScript). Also, my use ofapplywas somewhat annoying, I know, but was necessary to accomodate Internet Explorer, which does not currently allow extension ofElement,Array, etc. which was my preference. I have requested that this be remedied in the forthcoming version 7, but we’ll see if that actually happens.
posted at 01:58 pm on September 22, 2005 by Aaron Gustafson
30 RE: 29
I’m probably more sleep deprived now than I was while writing my original message. I appologize in advance for any incoherance on my part.
As long as there’s an effective way to exclude an area, such as class=“ignore”, I can’t really think of any situation that can’t be handled. It may not be the most efficient possible way, especially if you end up having to exlude 3 elements in order to include 2 children of some parent element, but it’d work. And I freeley admit any situation like this would be pretty rare. So that answers my original concerns quite nicely.
Also, the link to your site that’s attached to your name is missing the : in http:// so something somewhere is being helpful and adding http:// in front of it, which kills the link.
posted at 01:39 pm on September 23, 2005 by Derek Pennycuff
Discussion Closed
New comments are not being accepted, but you are welcome to explore what people said before we closed the door.
Got something to say?
Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.
Create a new account or sign in below if you’d like to leave a comment.
Subscribe to this article's comments: RSS (what’s this?)






21
Perhaps I should have explicitly stated so in the article, but I do not recommend using the simple onload function I used in the sample files to run the script. I do recommend using some method of onload handling (of which there are numerous methods available).
posted at 07:55 pm on September 20, 2005 by Aaron Gustafson