PDA

View Full Version : How to...(Print an image on Page)


Bhavit1
08-15-2002, 10:39 AM
Hi guys,
I want to print an image on the page using a button or a printer image. Can anyone provide me with the code to do this? I dont want to print the whole HTML page but just the specific image on that page(It is an Organization chart in the form of image)
Code or link to the code??

scoutt
08-15-2002, 10:48 AM
only if the image is the only thing on the page. you can't jsut pick an image and print it as the whole page will print. once the user hits print the OS takes over and the browser has no control. so you will have to make the image a popup or another window so it is the only thing on the page.

Jon Hanlon
08-15-2002, 07:19 PM
Pop this in the <head> section:

<link rel="alternate" media="print" href="/images/orgChart.gif">


Then, to print, use:

<img src="/images/printer.gif" onclick="doPrint()">

<script language="Javascript">
function doPrint() {
if (!window.print) { //IE4 etc.
alert("Please Print using the toolbar")
} else {
window.print()
}
}
</script>


Note that there's no way to stop the printer settings box from appearing when a user clicks the image. This is by design, so sites can't print rogue material without users' permission.

Bhavit1
08-16-2002, 04:22 AM
I have tried the code and it is working absolutely fine. thanks a lot. It now does print out the image and also it is showing the Print dialogue box.
Gr8.
Thanks again!!