View Full Version : Targeting a frame w/ javascript
Tombo
11-14-2002, 08:38 PM
The head script:
<script>
<!--
function showimage(imagesrc){
document.open()
document.write('<title>Title</title><body bgcolor="#000000"><img src="'+imagesrc+'"></body>')
document.close()
}
//-->
</script>
The body script (the actual link):
<a href="" onClick="showimage('image.jpg');return false">link</a>
Basically, clicking the link opens an image like a regular link to an image would, except the background will be black.
I want to have the image appear in another frame, but adding a target tag in the a href tag doesn't get the job done. I'm assuming the target has to be declared in the actual head portion of the script, but I've no idea how to do it. A little help?
beetle
11-14-2002, 09:24 PM
Well, you aren't targeting a frame if you are using window.open. Which do you intend to do?
Also, if you really do want the images in a popup, check out this script (http://www.codingforums.com/showthread.php?s=&postid=47220#post47220) I just posted :D
Tombo
11-14-2002, 09:27 PM
I used to have a pop-up image script, but it began to become tedeous when my photo album has over 500 photos. So, instead of having pics pop up in their own window, I wanted to use a frame set with 3 frames. One with albums, one with thumbnails that are displayed for each album, and one that will display the image who's thumbnail is clicked.
All I wanted was for the image to appear on a black background, which is what my script does. Only, I can't seem to get it to target another frame. Is there a way to modify the document.open tag to have it target a specific frame?
beetle
11-14-2002, 11:16 PM
You don't want to use document.open at all! Just give the image in the frame an id, like 'focusPic' or something like that. Then, your links should look like this...
function doImage(e) {
var a = (document.all) ? e.srcElement : e.target;
if (a.nodeName != "A") return;
top.frames['frameName'].document.getElementById('focusPic').src = a.getAttribute("href");
return false;
}
<div onClick="return doImage(event)">
<a href="image1.jpg"><img src="image1_small.jpg"></a>
<a href="image2.jpg"><img src="image2_small.jpg"></a>
<a href="image3.jpg"><img src="image3_small.jpg"></a>
</div>
whammy
11-15-2002, 12:41 AM
You might also like the script I posted (which DOES still use a popup), where you just put the image name, width, and height in a querystring, and process them all using ONE page. You'd have to customize it to meet your needs but I think it's a rather easy way of accomplishing this.
http://www.codingforums.com/showthread.php?s=&threadid=9006&highlight=QueryString
glenngv
11-15-2002, 01:23 AM
Originally posted by beetle
Well, you aren't targeting a frame if you are using window.open. Which do you intend to do?
you can target a frame using window.open:
window.open(url,frameNameHere)
whammy
11-15-2002, 01:25 AM
Good point Glenn... it's been so long since I used that I forgot that myself.
:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.