Click to See Complete Forum and Search --> : Image to print feature


jjbarnone
11-08-2007, 11:36 AM
Hello everyone,

Pretty basic question, but I'm unable to answer it - so here goes. I would like to place an image on my web site so when a user clicks on it, it opens up in a new box/window and the print screen box also comes on.

The best example I can give is when you go to Google maps, and click on the print button once you have your map, it opens up the map in a smaller box and your print box comes up to print that specific portion of the map.

Do any of you know a quick way to do this. I primarily use plain HTML, CSS, and very few javascripts. I can create the popup portion just fine. I just want to find out how to make the print box open up when it opens the image.

Thanks,
jj

gil davis
11-08-2007, 11:49 AM
<a href="theimageurl" onclick="popup=window.open(this.href,'','');popup.onload=window.print();return false"><img src=...></a>

jjbarnone
11-08-2007, 01:01 PM
I can't seem to get that to work?

in my header section I have this for a popup feature...it basically works if the person has javascript turned off - a blank window opens and sends the visitor to the intended path...


<script type="text/javascript">
<!--

function myOpenWindow(winURL, winName, winFeatures, winObj)
{
var theWin;
if (winObj != null)
{
if (!winObj.closed)
{
winObj.focus();
return winObj;
}
}
theWin = window.open(winURL, winName, winFeatures);
return theWin;
}

var myWin = null;

//-->
</script>



and then in the HTML section, I have this for the link attributes:



<a href="test.html" target="_blank" onclick="myOpenWindow(this,'Window Name','height=400,width=750,scrollbars=no');onload=window.print();return false">Image goes here</a>

There are different variations, the major one is that the popup box does not load until you close the print box?

Another variation is that the print box comes up but the popup disappears (goes to the background behind the original page) and the print box is created for the original page which it will print, not the popup box? I tried different variations like popup.onload=window.print(), pop.onload=window.print(), window.onload=window.print() - but nothing seems to work. Do I need to focus the popup box?

gil davis
11-09-2007, 06:45 AM
That is what happens when you don't post code in the first place. ;-)

function myOpenWindow(winURL, winName, winFeatures, winObj) {
var theWin;
if (winObj != null)
{if (!winObj.closed)
{winObj.focus();
winObj.onload = window.print();
return winObj;}
}
theWin = window.open(winURL, winName, winFeatures);
theWin.onload = window.print();
return theWin;
}

jjbarnone
11-10-2007, 10:34 PM
I slipped that in there and it works....had to put a settimeout feature for a second to prevent it from loading the thing too soon. Thanks for the help...