PDA

View Full Version : random iframe content is white while loading



myyoungfamily
11-11-2005, 06:22 PM
Please help...

Here's the problem:

As the script loads my random content into the iframe the iframe is a white area. I'm not having transparency problems because when the content loads the background shows through.

Why is my iframe white while the content is being loaded into it?
Is this just an Internet Explorer problem?

Here's the DD script:
http://www.dynamicdrive.com/dynamicindex17/randomiframe.htm

Here's my page:
http://www.myyoungfamily.com/newhome.htm

-Jonathan

jscheuer1
11-11-2005, 07:35 PM
The reason is that the iframe isn't populated with anything until the page has otherwise fully loaded because, initially it has no source. Find this line:


document.write('<iframe id="dynstuff" src="add page here" '+iframeprops+'></iframe>')

I've added in red where you can put a page name. Make a blank page with the same background color as your page and put it here. It will be overwritten in the display by the random content, once the page loads. Sometimes this is not enough. We may need to set its visibility to hidden to begin with then make it visible once the random content is loaded into it. Let me know how the first idea works. I also once made an iframe that had 0 opacity until loaded, that is another approach we could try.

jscheuer1
11-11-2005, 07:40 PM
Here is the hiding idea (additions red):


//No need to edit after here
if (ie||dom)
document.write('<iframe id="dynstuff" style="visibility:hidden;" src="" '+iframeprops+'></iframe>')

function random_iframe(){
if (ie||dom){
var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
iframeobj.src=randomcontent[Math.floor(Math.random()*randomcontent.length)]
iframeobj.style.visibility='visible'
}
}

window.onload=random_iframe

</script>

myyoungfamily
11-11-2005, 07:53 PM
That worked great thanks!

You've made me currious though. How do you set the visibility or make the opacity 0?

-Jonathan

myyoungfamily
11-11-2005, 07:54 PM
You read my mind...

myyoungfamily
11-11-2005, 07:58 PM
Well we're 1 for 3...
Idea 1 worked but idea 2 didn't
Maybe three is a charm. Can we try the opacity thing?
-Jonathan

jscheuer1
11-12-2005, 04:14 AM
Looking back over my notes, the opacity trick is very similar to the visibility one, except that I used an on page style sheet to set the initial style for the iframe. That approach may coax the visibility method to work as well. However, it also relied upon having a source for the iframe (as in solution 1 from this thread), guess I was covering all the bases. In short, if method 1 works, stick with it. OK, for the opacity method, put this in the head:


<style type="text/css">

#dynstuff {
filter:alpha(opacity=0);
-moz-opacity:0.00;
opacity:0.00;
}

</style>

Add to the script as shown:


function random_iframe(){
if (ie||dom){
var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
iframeobj.src=randomcontent[Math.floor(Math.random()*randomcontent.length)]
if (iframeobj.filters)
iframeobj.filters[0].opacity=100;
else{
iframeobj.style.MozOpacity=1.0;
iframeobj.style.opacity=1.0;
}
}
}