PDA

View Full Version : Getting images to print in Photo Album Script



Devillishdeb
04-16-2008, 01:19 PM
1) Script Title: Photo Album script v2.0

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/photoalbum.htm

3) Describe problem: I have used the above script to create a gallery which shows colouring pages. The user clicks on the thumbnail image which then brings up another window showing a larger version of the image. I then want the user to be able to print the larger image either on click or some other way? I have tried some javascript code but have been unable to get it to work because of the way the code is set out in this script. Can anyone help?

ddadmin
04-17-2008, 04:08 AM
Are you using the onphotoselect event handler and window.open() to get the enlarged image to open up in a new window when the thumbnail is clicked on? Something like:


thepics.onselectphoto=function(img, link){
if (link!=null) //if this image is hyperlinked
window.open(link.href, "", "width=800, height=600, status=1, resizable=1")
return false //cancel default action when clicking on image, by returning false instead of true
}

If so, why not just tweak window.open() to show the browser's menubar within the pop up window, which gives the user easy access to printing what's inside it:


thepics.onselectphoto=function(img, link){
if (link!=null) //if this image is hyperlinked
window.open(link.href, "", "width=800, height=600, status=1, resizable=1, menubar=1")
return false //cancel default action when clicking on image, by returning false instead of true
}

Nile
04-17-2008, 04:55 AM
Well, with that window that opens up, I think that you should make it 1 html file that does all the work. With this HTML file, it will look in the location, for example:
Image.html:


var allimg = new Array;
var allimg = ["pig.png","dog.gif","jone.jpg"];
for(i=0;i<=allimg.length-1;i++){
if(document.URL == "http://dynamicdrive.com/?picid="+i){
document.write('<img src="'+i+'" alt="Click on me to Print" title="Click on me to Print" onClick="window.print()" />');
}
}

Now, to open that file, your gonna want to have a link on every image, in my example, as you can see in the highlighted, I have 3 images in total. One named pic.png, one named dog.gif and one named jone.jpg. To open them, on every image put:


onClick='window.open("image.html?picid="+this.src, "", "width=800, height=600, status=1, resizable=1")'
I hope this helps. I havn't tested any of it yet.

Devillishdeb
04-17-2008, 12:12 PM
Thanks for the quick replies. Got it working using ddadmin code. I'm a relatively new coder and sorry nile but that code looked a bit complicated for me. Thanks for your help :D

Nile
04-17-2008, 12:15 PM
Alright, glad to help anyway.