Would it be possible to code a custom FF extension that by just clicking the button, prints to a pre-configured printer a snippet of text from the page it's on? I basically need to print an address label. I can place unique, identifying tags around the address I need printed but I want to reduce the number of clicks invloved to a minimum. So with this solution I was hoping to reduce it to one click. Would this be technically possible? And while we're at it, can you make it?
Probably. I think what you'd have to do is grab the selected text then create a new web page formatted with that text, suitable for printing. Both of these techniques I know are possible based on various FF plug-ins I use. I started writing a couple FF plugins a while back but got distracted before finishing. But I suggest you locate a couple plugins which do these two things (grab selection, create new custom page) and pick apart their source code. A lot of what I learned came from this technique.
Off topic, but PM me the info on text link advertising on your NES ROMs site. I saw from the site you have an option for it.
I'm not sure if this is 100% what you want, but it's a bookmarklet (a lot quicker to do than an extension). javascript:(function(){ /* Get text */ var txt = window.getSelection(); /* hide EVERYTHING */ var el = document.createElement('style'); el.setAttribute('type', 'text/css'); el.innerHTML = '@media print { body { display: none; } #showforprint { display: block; } }'; document.getElementsByTagName('head').item(0).appendChild(el); /* show the text we selected */ var nd = document.createElement('div'); nd.setAttribute('id', 'showforprint'); nd.innerHTML = txt; document.getElementsByTagName('html').item(0).appendChild(nd); /* and print */ window.print(); })(); Code (markup): You select something, click that, then hit enter, and it'll print. Hopefully it does what you're looking for.
Sounds good. But I'd like to skip having to go to a custom page. I can custom format the text on the initial page if need be, no problem. It's only a back-end order processing page, so if it can;t take it from the current address being displayed I can make a custom prepared snippet somewhere else on the page, possibly even hidden if need be.
Wow! Hold on a second though, I know nothing whatsoever about anything that isn't PHP/HTML. Where would that go? Embedded in the page? How do I get the clickable 'button' or whatever it is? How do I skip having to select the printer (we have 4 but the 5th will be the label printer)?
My new colleague knows his JS stuff, it actually goes in the html header, with a button where you want it to go.
I have it working now and that is such a nice solution whilst I was thinking all complicated. My colleague is going to adjust it so the text will have a div tag around it and that way you don't have to select the text first, it will be pre-loaded. One issue left. Skipping the print dialogue window. Can I pre define the chosen printer's ID somehow?
What you should've done for this is right clicked your bookmarks toolbar, clicked "New Bookmark", then put that exact code into the "Location" field. You don't want to put it in the HTML header. I don't think JavaScript can bipass the print dialogue: If it could, I could write a script that wastes all your ink. Oh, and to modify it to be a div, change: var txt = window.getSelection(); Code (markup): Into: var txt = document.getElementById('YourIdGoesHere').innerHTML; Code (markup): Very easy fix.
Thanks again! I figured it would be better to have it in the html embedded as I have now since that way it will work in all of our staff's broweser without being dependant on browser settings (as I initially envisaged). Because I now stuck it in the code, it's available to all, in FireFox as well as IE without any intervention necessary from individual's parts first. Or do you reckon this has a downside I overlooked? You explicitly state "You don't want to put it in the HTML header.", why is that?
I was under the impression you needed it for multiple pages. If you're only using it on a single page (or dynamically added to multiple pages), it realy doesn't matter.
Yeah it's for one page, the order processing page, only. Thanks for your ideas, they've been a great help. Now off to buy a labeling printer.
Besides the printer choice, one issue remains. It prints without any formatting. And address that's on the page in a <td> like this: <td class="main">Mr John Smith <br>1a Street Road<br>Town, County<br>PO5 TC0, Great Britain<br /><br /> <INPUT TYPE="button" NAME="myButton" VALUE="Select Text & Print Label" onClick="print_label()"> </td> Code (markup): Comes out as plain text in one line like this: I've tried adding \n or \r behind each line but to no avail. Any ideas on how to keep formatting?