View Full Version : how to get at div property in iframe
firepages
11-18-2002, 04:23 AM
Hi, I use the following code for hiding an object in the main window...
function hide(obj) {
div=B.dom?document.getElementById(obj).style:B.ie4?document.all[obj].style:B.ns4?document.layers[obj]:0;
div.visibility = (B.ns4)? "hide" : "hidden"
}
is there anyway I can target and show/hide a div in an iframe ?
(eg window.iframe_name.div_name)
?
cheers!
beetle
11-18-2002, 04:33 AM
An iframe on a page belongs to the frames collection of that window so...
self.frames['iframeName']
firepages
11-18-2002, 04:39 AM
ah , whilst I am here :)
how would I refresh 1 iframe from within another iframe in the same docment I mean if I had...
window.iframe1
window.iframe2
how could I get iframe2 to reload iframe1 without reloading the main window ?
full of questions today ain't I :D
beetle
11-18-2002, 04:48 AM
Heh, no problem. To be honest with you, I almost always use absolute references to frames when using them. The case is VERY rare when I think it is not the preferred method (such as 3-4 nested sets of frames...ya that happens often :rolleyes:) This rule sees more flexibility when iframes come into play...
Making an absolute reference to a frame is just like an absolute link...start from the top and go down, and coincidentally, the keyword for finding the top window in a nested frame structure is top!
top.frames['iframe1']
top.frames['iframe2']
Being absolute, these references will work accurately from ANYwhere within the window/frame structure
Note: I'm not sure if using the frames collection is necessary (as opposed to the dot-syntax), but it is my preference)
firepages
11-18-2002, 04:48 AM
cheers muchly Beetle ,
//
div=B.dom?window.frames[frame].document.getElementById(obj).style:B.ie4?document.all[obj].style:B.ns4?document.layers[obj]:0;
div.visibility = (B.ns4)? "show" : "visible"
//
did the job , (I know the NS4 bit will cark it BTW)
beetle
11-18-2002, 04:51 AM
Shouldn't that be...
var f = window.frames[frame];
div=B.dom?f.document.getElementById(obj).style:B.ie4?f.document.all[obj].style:B.ns4?f.document.layers[obj]:0;
???
It seems you only satisfied the getElementById condition in your ternary....
firepages
11-18-2002, 05:27 AM
Hi, Beetle the exact code I was using was ...
function hideiframe(frame,obj) {
if(BB==1){
div=B.dom?window.frames[frame].document.getElementById(obj).style:B.ie4?document.all[obj].style:B.ns4?document.layers[obj]:0;
div.visibility = (B.ns4)? "hide" : "hidden"
}}
(the 'BB' bit is just a check that the browser detection has finished)
& yes you are right I have ignored IE4 there which I must fix !, as for NS4 it wont recognise the iframe anyway and NS4 users won't actually be able to view this page, just I reuse a lot of existing code hence the dinosaur layers bit :)
cheers again
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.