Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Idea for Making Printable Web Pages

Name: Anonymous 2008-09-08 2:21

Hey /prog/rammers, I know that web developers sometimes struggle with ideas for how to properly render text via CSS, etc. when printing a webpage to paper. You can't click hyperlinks on paper, so some information is lost in the printing.

The solution has always seemed obvious to me, but until today I was too lazy to do anything about it. So my idea (and it's probably actually been done a billion times before by other people) is to just turn every anchor tag into an endnote.

Just put this in your page and then execute makeEndnotes() whenever you want to create the endnotes and get rid of the hyperlinks for printing. You can include a different CSS file that defines printing (nice margins, serif font, no background, etc.).

Anyway, here's the function. I tested it out on a google results page and I thought it looked passable. There are things I could do to make it better, such as have the call number appear after a comma or period instead of before it (to make it "correct"), but I'm going to bed because tomorrow I start up interviews.

function makeEndnotes() {
                var anchors = document.getElementsByTagName('a');
                if (anchors.length>0) {
                    endnoteDiv=document.createElement('div');
                    endnoteDiv.id="endnotes";
                    document.body.appendChild(endnoteDiv);
                   
                    A=document.createElement('hr');
                    B=document.createElement('h1');
                    B.innerHTML = 'Endnotes';
                    document.getElementById('endnotes').appendChild(A);
                    document.getElementById('endnotes').appendChild(B);
                }
                //for (i=0;i<anchors.length;++i) anchors[i]=normalizeURL(anchors[i],TODO);
                for (j=0;j<anchors.length;++j) {
                    C = document.createElement('span');
                    C.innerHTML = '<sup>'+(j+1)+'</sup>'+anchors[j].href;
                    A = document.createElement('span');
                    A.innerHTML = anchors[j].innerHTML+'<sup>'+(j+1)+'</sup>';
                    anchors[j].parentNode.insertBefore(A,anchors[j]);
                    E = document.getElementById('endnotes');
                    B = document.createElement('br');
                    E.appendChild(B);
                    E.appendChild(C);
                }
                while (document.getElementsByTagName('a').length>0) document.getElementsByTagName('a')[0].parentNode.removeChild(document.getElementsByTagName('a')[0]);
            }

Name: Anonymous 2008-09-08 2:21

                    B = document.createElement('br');
                    E.appendChild(B);
                    E.appendChild(C);
                }
                while (document.getElementsByTagName('a').length>0) document.getElementsByTagName('a')[0].parentNode.removeChild(document.getElementsByTagName('a')[0]);
            }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List