Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing image (and other)

Status
Not open for further replies.

ptichka

Programmer
May 28, 2002
19
US
Hello everyone!
I need to be able to print and save images one by one on my web page. I know how to print the entire page, but can I print one image using javascript.

(just like the options available if the user right clicks on the image)

Thanks for helping.
 
Does this work?
Code:
function printImage(imgSrc){
  var imgWin=window.open(imgSrc);
  imgWin.focus();
  imgWin.print();
  imgWin.close();
}

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 

I think what Adam has given you will be the only way to do this... The image object doesn't have a print() method, and trying to create an iframe with the image as the src, print it, and then destroy it, proved far too hard (I gave up after about an hour ;o)

Dan
 
Adam,
I tried the function you suggested. It does work in IE, but I can't make it work in Netscape. It doesn't even open a new window with the image. DO you know why?
 
No, I don't. Do you get an error? I wonder if it has to be in a document in order to print in NS. Try this:
Code:
function printImage(imgSrc){
  var imgWin=window.open();
  imgWin.document.write("<html><body><img src='");
  imgWin.document.write(imgSrc);
  imgWin.document.write("'></body></html>");
  imgWin.document.close();
  imgWin.focus();
  imgWin.print();
  imgWin.close();
}

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top