Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Print Selection in Firefox (all?)

    This is something I created in response to a thread on the mozillaZine forums, but thought that some Lounge users might want to try out.

    The problem is that when printing a selection, Firefox often maintains the relative position of the material. This can cause it to run past the right margin or simply to be in an illogical location on the page.

    The workaround is to snip out the selection, hide the rest of the document, and have just the selected material on the page. The quickest way to make the necessary script code available in Firefox is to create a "bookmarklet". The following is some pretty rough "beta" code, but it works in my little test so far. (In Firefox; not tested elsewhere.) After printing, you have to reload the page to return it to normal.

    Here's how you can install it:<UL><LI>Open the Bookmarks Manager dialog (Bookmarks>Organize Bookmarks...)

    <LI>Click Bookmarks at the top of the "tree" in the left column, then click the New Bookmark button

    <LI>Copy and paste this into the Name space, or choose a Name you like:

    <code>Crop4Print v0.2</code>

    <LI>Copy and paste the following into the Location space:

    <code>java script:var sel=window.getSelection(); if(!sel.isCollapsed){var rng=sel.getRangeAt(0); if(!rng.collapsed){var docfrag=rng.cloneContents(); var rng2=document.createRange(); rng2.selectNodeContents(document.body); var myContainer=document.createElement("DIV"); rng2.surroundContents(myContainer); myContainer.setAttribute("id", "hideMe"); myContainer.style.display="none"; rng2.detach(); document.body.appendChild(docfrag); rng.detach();}} void 0;</code>

    <LI>Copy and paste the following into the Description space (it's the URL to the mozillaZine thread, in case problems or questions come up in the future):

    <code>http://forums.mozillazine.org/viewtopic.php?t=513572</code>

    <LI>Click OK to save it[/list]The way bookmarks sort in the Bookmarks Manager and on the menu is somewhat unpredictable. It should be there somewhere. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    To test it out, select something on a page and then run the bookmarklet. It should move the selected material to the left side and "white out" the rest of the page. Sometimes it takes 5-8 seconds, for no apparent reason. It's possible that there will be color problems because the selection is taken out of its original context... I look forward to feedback.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Oct 2001
    Location
    Lexington, Kentucky, USA
    Posts
    12,107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    How did you know I needed this! You must havetelepathic powers! <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> I periodically DO like to print something from a sports or news page to take to one of my friends at the nursing home who doesn't have internet (or computer) access. It's always been a mess. I hope you'll forgive <img src=/S/grin.gif border=0 alt=grin width=15 height=15> my brashness, for I called the bookmarklet "JScher Print Thingie" and it was at the very end of my bookmark list. I simply dragged it up near the top. So now, I assume you'd like fellow Loungers to comment HERE rather than in that Mozilla thread, huh?

    I just tried it four times, on four different pages and it worked like a dream. I haven't actually sent any to the printer yet for I <img src=/S/blush.gif border=0 alt=blush width=15 height=15> haven't rectified my ink cartridge problem yet. (another thread) I saw a medium-dark gray background on one selection I made but the others were white backgrounds. I tried both refresh (F5) and pressing the Back button, and both methods did as you would expect them to. Good (and perfect timing!) job and I hope you'll keep this thread up if you make any changes or improvements. Thank You.

    PS When I get my ink problem corrected, I want to check that gray background situation, for I wouldn't want to waste color ink printing text on a colored background. More later...

  4. #3
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    The printing of background colours are (I believe) controlled in the Page Setup screen - you can see the impact of the option directly by looking at a Print Preview...
    Attached Images Attached Images
    • File Type: gif x.gif (9.3 KB, 0 views)

  5. #4
    Plutonium Lounger
    Join Date
    Oct 2001
    Location
    Lexington, Kentucky, USA
    Posts
    12,107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    Good catch, Leif and thanks! I'll try to stop at the CompUSA this afternoon and fix my "ink" problem. BTW, I forgot to mention in my post to Jefferson that what I've BEEN doing is copying the text I want to print, pasting it into a NoteTab Lite empty document and printing that. Jefferson's script makes the process nice, smooth and direct for me, and I hope others too.

  6. #5
    4 Star Lounger
    Join Date
    Feb 2006
    Location
    Cape Cod, Massachusetts, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    Your code works fine here. Thanks ! It also works quickly, not with a 5 to 8 sec delay.
    It solves a bigger problem for me, however, as I was never able to get Firefox 2 to print just a selection. How is one suppose to accomplish that?
    Paul

  7. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Print Selection in Firefox (all?)

    > I was never able to get Firefox 2 to print just a selection

    Once the text is selected, the radio button for "Selection" becomes enabled in the Print dialog. However, it's all too easy to forget to select that radio button. Sadly, they haven't yet checked in the telepathy module...

  8. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Print Selection in Firefox (all?)

    > I haven't actually sent any to the printer yet for I <img src=/S/blush.gif border=0 alt=blush width=15 height=15> haven't rectified my ink cartridge problem yet.

    I did all of my testing with a PDF print driver. The forests of Indonesia are safe... for the moment. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

  9. #8
    4 Star Lounger
    Join Date
    Feb 2006
    Location
    Cape Cod, Massachusetts, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    Ah, the Print dialog box. <img src=/S/blush.gif border=0 alt=blush width=15 height=15> . Thanks.

    It would be nice if there was a selection button in the Print Preview window as well . Please don't tell me I missed a button there also.

    Paul

  10. #9
    Plutonium Lounger
    Join Date
    Oct 2001
    Location
    Lexington, Kentucky, USA
    Posts
    12,107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    <hr>...I haven't actually sent any to the printer yet for I <img src=/S/blush.gif border=0 alt=blush width=15 height=15> haven't rectified my ink cartridge problem yet...<hr>
    I did and it does (work like a charm that is). Thnx again

  11. #10
    5 Star Lounger PaulB's Avatar
    Join Date
    May 2002
    Location
    Ottawa, Ontario
    Posts
    763
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    >Once the text is selected, the radio button for "Selection" becomes enabled...

    I learned something new today. Thanks,
    Regards,
    PaulB

  12. #11
    Silver Lounger
    Join Date
    Oct 2002
    Posts
    1,993
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    This works great! You can call it 2.0 (instead of 0.2) if you like. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Thanks! With your code one can also preview the selection.

  13. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Print Selection in Firefox (all?)

    Thanks! I'm calling this revised version 0.5...

    What's New? A (non-printing) button appears below your selection. Click the button to restore the page.

    To install:<UL><LI>Open the Bookmarks Manager dialog (Bookmarks>Organize Bookmarks...)

    <LI>Click Bookmarks at the top of the "tree" in the left column, then click the New Bookmark button

    <LI>Copy and paste this into the Name space, or choose a Name you like:

    <code>Crop4Print v0.5</code>

    <LI>Copy and paste the following into the Location space:

    <code>java script:var sel=window.getSelection(); if(!sel.isCollapsed){var rng=sel.getRangeAt(0); if(!rng.collapsed){var docfrag=rng.cloneContents(); if(!document.getElementById(%22divHideMe%22)){var rng2=document.createRange(); rng2.selectNodeContents(document.body); var myContainer=document.createElement(%22DIV%22); rng2.surroundContents(myContainer); myContainer.setAttribute(%22id%22,%22divHideMe%22) ; rng2.detach();} myContainer.style.display=%22none%22; if(document.getElementById(%22printFrag%22)){var myFrag=document.getElementById(%22printFrag%22); while(myFrag.firstChild) {myFrag.removeChild(myFrag.firstChild);} myFrag.style.display=%22block%22;}else{var myFrag=document.createElement(%22DIV%22); myFrag.setAttribute(%22id%22,%22printFrag%22); document.body.appendChild(myFrag);} myFrag.appendChild(docfrag); rng.detach(); var myP=document.createElement(%22P%22); myFrag.appendChild(myP); myP.setAttribute(%22id%22,%22killBtn%22); var myBtn=document.createElement(%22INPUT%22); myP.appendChild(myBtn); myBtn.setAttribute(%22type%22,%22button%22); myBtn.setAttribute(%22value%22,%22Return to Page%22); myBtn.setAttribute(%22onclick%22, %22document.getElementById(%27divHideMe%27).style. display=%27block%27; document.getElementById(%27printFrag%27).style.dis play=%27none%27;%22); myStyle=document.createElement(%22STYLE%22); myFrag.appendChild(myStyle); myStyle.setAttribute(%22type%22,%22text/css%22); myStyle.setAttribute(%22media%22,%22print%22); myStyle.innerHTML=%22#killBtn{display:none}%22;}} void 0;</code>

    <LI>Copy and paste the following into the Description space (it's the URL to the mozillaZine thread, in case problems or questions come up in the future):

    <code>http://forums.mozillazine.org/viewtopic.php?t=513572</code>

    <LI>Click OK to save it[/list]Basically, it's the same, but repeatable. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> In this post I was careful to preserve the %22 notation for " marks. I thought it was necessary but perhaps not??

  14. #13
    Plutonium Lounger
    Join Date
    Oct 2001
    Location
    Lexington, Kentucky, USA
    Posts
    12,107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    I'm still testing the first one you posted, not this version. But, this morning I discovered a malady. Quite some time ago, you assisted and guided me in adding the "capability" lines to my Firefox prefs file to stop some of the annoying ads without add-ons or extensions. That's been working fine and still does. However, when I went to the USA Today page this morning to select a section of a story for someone, your print thingie would come up. I got out and removed the three "capability" preferences and the print script works just fine. You'll see below that javascript is disabled at USA Today, so I guess that's it, but I'm gonna continue to experiment because even WITH those prefs lines, I'm able to select text from CNN just fine. (I'm intentionally breaking the second line below to prevent wide screen.)

    user_pref("capability.policy.cnnstuff.javascript.e nabled", "noAccess");

    user_pref("capability.policy.cnnstuff.sites", "ads.cnn.com 2mdn.net a.cnn.net advertising.com atdmt.com atwola.com ad.doubleclick.net
    doubleclick.net questionmarket.com xads.zedo.com m.2mdn.net js.usatoday.com usatoday.com");

    user_pref("capability.policy.policynames", "cnnstuff");

  15. #14
    4 Star Lounger
    Join Date
    Feb 2006
    Location
    Cape Cod, Massachusetts, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Selection in Firefox (all?)

    Version 0.5 performs well in my initial tests.
    As long as you are button building, would you consider adding Preview and Print buttons? Perhaps the Print button could be a Print & Return button.

    Paul

  16. #15
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Print Selection in Firefox (all?)

    Al, thanks for the feedback. I don't understand the interaction between a site's permissions and bookmarklets; I hadn't noticed it before and I'm having trouble testing it (perhaps NoScript is overriding the policy somehow??). Try removing just the last domain (usatoday.com), and see whether that is enough to run the script on text in the page.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •