View Full Version : Trageting another freme w/ javascript (2)
Tombo
11-15-2002, 05:27 PM
I have a frameset with 2 frames. The script in the first frame generates a page and I'd like it to be displayed in the second frame.
In simpler terms, in one frame, a script is run. I would like it to target the second frame.
The script that creates the page is triggered by a link on the first frame, but using target="" in the a href="" tag doesn't do it. I'm using the document.open, document.write, and document.close tags. I've tried a few java forums, with little help. Any ideas?
The script itself (if it will display):
function showimage(imagesrc){
document.open()
document.write('html page text inserted here')
document.close()
The a href contents:
a href="" onClick="showimage('img/01.jpg');return false"
Any help?
beetle
11-15-2002, 05:34 PM
Are you manipulating text in the new frame too? Or just showing an image? Did you test this method I showed in you last post?function doImage(e) {
var a = (document.all) ? e.srcElement : e.target;
if (a.nodeName != "A") return;
top.frames['frameName'].document.getElementById('picId').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>
requestcode
11-15-2002, 05:36 PM
Try this:
parent.frame_name.document.write("HTML HERE")
parent.frame_name.close()
I don't believe you want the document.opent.
Tombo
11-15-2002, 05:36 PM
One of the variables I'll be sending the function through the a href link will be a brief description of the photo, so I can't use <div>.
The script you gave me will work if the photos are shown on the same page as the links accessing them, but it won't work if the <div> is in another frame.
I just want to know if there is a way to declare a frame that my script will generate a page in. :S
Tombo
11-15-2002, 05:38 PM
YES, parent.frame_name works.
MAJOR Kudos.
:D :D :D
beetle
11-15-2002, 06:07 PM
Glad you got it working Tombo.
However, I'd like to note that this could be done using the innerText or innerHTML properties of a DIV, or by accessing the nodeValue of it's firstChild. In the page with the thumbnails...
<script type="text/javascript">
function doImage(e) {
var a = (document.all) ? e.srcElement : e.target;
if (a.nodeName != "A") return;
var f = parent.frame_name;
f.document.getElementById('ssPic').src = a.getAttribute("href");
f.document.getElementById('ssDesc').innerText = a.getAttribute("desc");
return false;
}
</script>
<div onClick="return doImage(event)">
<a href="image1.jpg" desc="Image 1 description"><img src="image1_small.jpg"></a>
<a href="image2.jpg" desc="Image 2 description"><img src="image2_small.jpg"></a>
<a href="image3.jpg" desc="Image 3 description"><img src="image3_small.jpg"></a>
</div>Where frame_name is the name of the frame. Then, in the frame that is to show the image/text<html>
<body bgcolor="black">
<img id="ssPic" src="blank.gif" />
<div id="ssDesc"></div>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.