Connecting Tech Pros Worldwide Forums | Help | Site Map

Mozilla - Changing iFrame source

bulldog8@lycos.com
Guest
 
Posts: n/a
#1: Mar 19 '07
I am having problems with changing a frames source file for Mozilla
(1.5.0.4). The followig code works for IE:

<script type="text/javascript">
var imgP = new Image();
function ShowPic(ShowThis, wdth, hght) {
imgP.src = "../pics/' + ShowThis + '"
xw = 500;
yh = 500*(hght/wdth);
window.document.getElementById("graphic").innerHTM L = '<img src="../
pics/' + ShowThis + '" width="' + xw + '" height="' + yh +
'"border="0">';

}
function ChangeList(oSel) {
window.document.getElementById("F1").src = oSel;
}
</script>

....
....
....

<div id="graphic">
<script>ShowPic("company_name.gif", 1255, 324)</script>
</div>
<p align="center">&nbsp;</p>
<td valign="bottom" width="17>
<img border="0" src="../images/
coner_right_top.gif" width="17" height="130">
</tr>
<tr>
<td class="blank" height="17" width="17</td>
<td class="blank" height="17" align="right"
width="527">
<img border="0" src="../images/
coner_right_bottom.gif" width="180" height="17"></td>
<td class="blank" height="17" width="17">
<img border="0" src="../images/coner_right.gif"
width="17" height="17></td>
</tr>
</table</td>
</tr>
<tr>
<td width="100%">
<p style="margin-bottom: 0; margin-top:0"
align="center">

<select size="1" name="D1"
onChange="ChangeList(this.options[ this.selectedIndex].value);" >
<option selected value="PlayList2.htm">September
2003</option>
<option value="PlayList1.htm">Urban Bistro X-Mas
Dinner</option>
</select></p>

<p style="margin-top: 0; margin-bottom: 0">
<iframe name="I1" id="F1" width="549" height="189"
src="PlayList2.htm">
Your browser does not support or is currently
configured not to display inline frames</iframe>
<p align="center" style="margin-top: 0; margin-bottom:
0">
....
....
....

Within the function:
function ChangeList(oSel) {
window.document.getElementById("F1").src = oSel;
}

I have tried
frames["I1"]
getElementsByName("I1")
.innerHTML
.src

but to no success. I do not think I can depend on the Java console to
help debug, because it indicates that
"window.document.getElementById("graphic").innerHT ML" has no
properties, when the ShowPic function antually works (it is called by
the clickable graphics in the iFrame).

Any help would be appreciated!

- Jon


Randy Webb
Guest
 
Posts: n/a
#2: Mar 19 '07

re: Mozilla - Changing iFrame source


bulldog8@lycos.com said the following on 3/18/2007 11:52 PM:
Quote:
I am having problems with changing a frames source file for Mozilla
(1.5.0.4). The followig code works for IE:
<snip>
Quote:
Within the function:
function ChangeList(oSel) {
window.document.getElementById("F1").src = oSel;
}
>
I have tried
frames["I1"]
getElementsByName("I1")
.innerHTML
.src
You don't set an IFrame's src, innerHTML, you set it's location.href
property.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
ASM
Guest
 
Posts: n/a
#3: Mar 19 '07

re: Mozilla - Changing iFrame source


bulldog8@lycos.com a écrit :
Quote:
I am having problems with changing a frames source file for Mozilla
(1.5.0.4). The followig code works for IE:
but it is not the right code to use ...

parent.myIframe.location = 'newImage.jpg';
(needs the iFrame has a NAME (not an ID), here : 'myIframe' )

or with DOM

document.getElementById('F1').location = 'newImage.jpg';

function ChangeList(oSel) {
document.getElementById('F1').location = oSel;
// or :
// parent.frames['I1'].location = oSel;
}

It would has been simpler to have iframe's name same as iframe's id



I do not understand at all why you need a function so complicated
to display an image ...
Quote:
var imgP = new Image();
function ShowPic(ShowThis, wdth, hght) {
imgP.src = "../pics/' + ShowThis + '"
xw = 500;
yh = 500*(hght/wdth);
window.document.getElementById("graphic").innerHTM L = '<img src="../
pics/' + ShowThis + '" width="' + xw + '" height="' + yh +
'"border="0">';
}

<style type="text/css">
#graphic { text-align: center; }
#graphic img { width: 500px; border: 0; }
</style>
<div id="graphic">
<img src="compagny_name.gif" alt="compagny logo" title="My compagny">
</div>


Variante (without css) :

<script type="text/javascript">
function ShowPic(ShowThis, wdth, where) {
where = document.getElementById(where);
where.src = ShowThis;
where.style.width = wdth+'px';
}
</script>
<div id="graphic" style="text-align:center">
<img src="" id="logo" alt="compagny logo" title="My compagny">
<script type="text/javascript">
ShowPic("company_name.gif", 500, 'logo');
</script>
</div>
Quote:
<div id="graphic">
<script>ShowPic("company_name.gif", 1255, 324)</script>
</div>
[...]
Quote:
<select size="1" name="D1"
onChange="ChangeList(this.options[ this.selectedIndex].value);" >
<option selected value="PlayList2.htm">September
2003</option>
<option value="PlayList1.htm">Urban Bistro X-Mas
Dinner</option>
</select></p>
>
<p style="margin-top: 0; margin-bottom: 0">
<iframe name="I1" id="F1" width="549" height="189"
src="PlayList2.htm">
Your browser does not support or is currently
configured not to display inline frames</iframe>
<p align="center" style="margin-top: 0; margin-bottom:
0">


Quote:
but to no success. I do not think I can depend on the Java console to
help debug,
JavaScript console
Quote:
because it indicates that
"window.document.getElementById("graphic").innerHT ML" has no
properties,
right because 'graphic' is not in the iFrame
('window' here is the iframe)
Quote:
when the ShowPic function antually works (it is called by
the clickable graphics in the iFrame).
so you try to reach 'graphic' in main page, no ?


probably :
parent.document.getElementById("graphic").innerHTM L
could do what you expect

but if you call the function ShowPic(blah)
*from the iFrame* you must do :

parent.ShowPic(blah);




--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
bulldog8@lycos.com
Guest
 
Posts: n/a
#4: Mar 19 '07

re: Mozilla - Changing iFrame source


On Mar 19, 6:22 am, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Quote:
parent.myIframe.location = 'newImage.jpg';
(needs the iFrame has a NAME (not an ID), here : 'myIframe' )
>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date- Hide quoted text -
>
- Show quoted text -

Thanks! The parent.<frame name>.location worked perfectly in both
Firefix and IE

- Jon

Closed Thread