Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reload - Refresh multiple iframes 1

Status
Not open for further replies.

DimisD

Technical User
Feb 7, 2007
15
GR
Hi there,

Can somebody please fix the code bellow? I have 2 iframes and i want to reload them with the buttons bellow them.

Also, if it is easy, i wonder if you can make three more functions
: refresh, history+, history-

thank you!


<html>
<head>
<script type="text/javascript">

function Reload () {
var f = document.getElementById('iframe1');
f.src = f.src;
}

</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><iframe name="iframe1" id="iframe1" height="200" width="300" src=" <td><iframe name="iframe2" id="iframe2" height="200" width="300" src=" </tr>
<tr>
<td><input name="button1" type="button" onClick="Reload();" value="Reload"> </td>
<td><input name="button2" type="button" onClick="Reload();" value="Reload"> </td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>
 
I'll do the first part for you, since you attempted it, you almost had it.
The function calls get changed to this:
Code:
 <td><input name="button1" type="button" onClick="Reload([!]"iframe1"[/!]);" value="Reload">     </td>
    <td><input name="button2" type="button" onClick="Reload([!]"iframe2"[/!]);" value="Reload">     </td>


The function gets changed like this:
Code:
function Reload (iframeID) {
var f = document.getElementById(iframeID);
if (iframeID == "iframe1") {
   f.src = "[URL unfurl="true"]http://www.cnn.com";[/URL]
}
else {
   f.src = "[URL unfurl="true"]http://www.bbc.co.uk"[/URL]
}




[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Thank you monksnake for your emmediate response!!
Strangely, the code does not work.:(. Im i doing something wrong????

thank you


<html>
<head>
<script type="text/javascript">

function Reload (iframeID) {
var f = document.getElementById(iframeID);
if (iframeID = "iframe1") {
f.src = "}
else {
f.src = "}

</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><iframe name="iframe1" id="iframe1" height="200" width="300" src=" <td><iframe name="iframe2" id="iframe2" height="200" width="300" src=" </tr>
<tr>
<td><input name="button1" type="button" onClick="Reload('iframe1');" value="Reload"> </td>
<td><input name="button2" type="button" onClick="Reload('iframe2');" value="Reload"> </td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>
 
I'll take a look at it and get it going. I have a bad habit of writing code that is not 100% correct untested.



[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Here you go, this is tested and it works:

Code:
<html>
<head>
<script type="text/javascript">

function Reload(iframeID) {
var f = document.getElementById(iframeID);
   if (iframeID == "iframe1") {
      f.src = "[URL unfurl="true"]http://www.google.com";[/URL]
   }
   else {
      f.src = "[URL unfurl="true"]http://www.msn.com";[/URL]
   }
}   

</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><iframe name="iframe1" id="iframe1" height="200" width="300" src="[URL unfurl="true"]http://www.google.com"></iframe></td>[/URL]
    <td><iframe name="iframe2" id="iframe2" height="200" width="300" src="[URL unfurl="true"]http://www.msn.com"></iframe></td>[/URL]
  </tr>
  <tr>
<td><input name="button1" type="button" onClick="Reload('iframe1');" value="Reload">     </td>
    <td><input name="button2" type="button" onClick="Reload('iframe2');" value="Reload">     </td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>

There were two errors in your code, one was here:
Code:
if (iframeID = "iframe1") {

needed a double equals.

The other was, the function Reload did not have closing brackets.

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top