• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Direct Print to a Printer

 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've used the following code to imitate a direct print to a printer using javascript. The terminology may not be sound but the code works. Hopefully this will help someone out there looking to print to a printer "directly". If you have a better alternative approach, what keep you from getting back sooner? :
================================================
// Set the frames source, basically your HTML
// page holding the javascript will be in one
// frame while this one will hold the data to
// print. Set the javascript page to be 100%
// width and the data page frame to be 0%
//==============================================
var purchasetxt = print_items.arguments[0];
window.parent.frames['display'].src = purchasetxt;
//=== Obtain the data frame object
upper_object = window.parent.frames['display'];
//=== Create a Web Browser Object
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

//=== Insert the Web Browser Object into
//=== the second frame's window upper_object.document.body.insertAdjacentHTML('beforeend', WebBrowser);
//=== Set focus to the second frame (i.e. data
//=== frame)
upper_object.focus();
//=== Execute the Web Browser Object upper_object.document.WebBrowser1.ExecWB(6,-1);
//=== Get rid of the Embedded Web Browser Object upper_object.document.WebBrowser1.outerHTML = "";
=================================================
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..

do you have a web page with this function works ?

thanks
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're lucky I noticed this cause I had another question I was looking for. Yeah, I do have a few applications that has this working on them. Mind you, the people using this normally run only IE but I do believe it has been tested on Netscape as well.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic