...

View Full Version : Call to page and load IFRAME



dsirois1
10-27-2006, 09:17 PM
How would I encode a URL on home.htm to open another page (index1.htm) which contains an Iframe with name="test" and id="test" and load it with include1.htm or include2.htm which resides in the same directory as index1.htm.

------------------------
Example: (button 1 needs encoding)

home.htm -> button 1 -> links to index1.htm

Index1.htm -> iframe name and id="test"

iframe "test" -> displays one of two includes as defined by button 1 encoding

brandonH
10-29-2006, 10:23 AM
<body>
<input type=button value=doit onclick="winOp('1');">
<script type=text/javascript>
var newWin='';
function winOp(incNum){
newWin=window.open("testing/testing/index1.htm", "mywin");SetIframe(incNum);
}
function SetIframe(incNum){
if(newWin.document.getElementById('test')){newWin.document.getElementById('test').src="include"+incNum+".htm";}
else{alert('the child window has not loaded yet or'+'\n'+'it does not have an iframe with id of test');
}
}
</script>
</body>




the only path you need to worry about setting is when you open the window for index1.htm. once index1.htm is open the browser will use the same directory for the include files, so all you have to do with the script is put the include file name in it. you can also pass a different variable value to the winOp() function to write from a different include file. such as winOp("2") to write include2.htm into the iframe.


I hope this is what you were looking for

dsirois1
10-29-2006, 03:43 PM
Thank you very much, I will play around with it.

dsirois1
10-29-2006, 04:07 PM
Which part do i edit to get it to open in the same window?

Also, which part tells which include # to use?

dsirois1
10-29-2006, 04:35 PM
Here is the code for the entire page. What am i doing wrong? I've placed the script in both the <body> and <head> positions.

This is where I am testing it http://www.acmearticles.com/test/


-------------
<html>
<head>
<title>index 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type=text/javascript>
var newWin='';
function winOp(incNum){
newWin=window.open("index2.htm", "mywin");SetIframe(incNum);
}
function SetIframe(incNum){
if(newWin.document.getElementById('test')){newWin.document.getElementById('test').src="include"+incNum+".htm";}
else{alert('the child window has not loaded yet or'+'\n'+'it does not have an iframe with id of test');
}
}
</script>
</head>

<body>
<input type=button value=doit onclick="winOp('1');">
<p>index 1</p>
<p><table width="100%" border="1">
<tr>
<td><iframe src="include1.htm" name="test" id="test" width="600" height="300" scrolling="no" frameborder="0">&nbsp;</iframe></td>
</tr>
</table>
</p>
</body>
</html>

-------------------

do i need any script within the include?

brandonH
10-29-2006, 07:41 PM
ok, i see the problem after going to your test page. the problem is that the first script i gave you calls the setIframe() function right after it opens the new window. the problem with that is the page has to load and the iframe has to exsist before the setIframe() function starts running.(this becomes a hassle when the page does not load quickly). the below scripts should correct that problem.


put this in main page:


<html>
<head>
<script type=text/javascript>
var newWin='';
var includeNum='';

function winOp(incNum){
includeNum=incNum;
newWin=window.open("testing/testing/index1.htm", "mywin");
}

function SetIframe(){
if(newWin.document){
newWin.document.getElementById('test').src="include"+includeNum+".htm";}
else{
alert('the child window has not loaded yet or'+'\n'+'it does not have an iframe with id of test');newWin.close();
}
}
</script>
</head>
<body>
<input type=button value=doit onclick="winOp('1');">
</body>
</html>


and put this inside each of your index.htm files:


<html>
<body>
<iframe src='' id=test name=test height=300 width=300></iframe>
</body>
</html>
<script type=text/javascript>
if(opener){
setTimeout("opener.SetIframe()",1000);
}
</script>


this only works if the iframe is in a new window, not in the main page.

and to have a different include.htm loaded change the part within the button's tag that reads winOp('1'); to winOp('2'); where the number in quotes is the number of the include.htm file.

dsirois1
10-29-2006, 07:43 PM
You were right in that the page I am linking from also contains an Iframe which is also named "test". To avoid confusion I should have deleted it.

I'll clarify:
What I need to do is: While on index1.htm be able to click one of two (or more) links that define the variable (include) and load on top of itself, index2.htm to include the defined include1.htm or include2.htm.

I removed the iframe on index1.htm to avoid confusion

--------------
<html>
<head>
<title>index 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type=text/javascript>
<!--

var newWin='';
function winOp(incNum){
newWin=window.open("index2.htm", "mywin");SetIframe(incNum);
}
function SetIframe(incNum){
if(newWin.document.getElementById('test')){newWin.document.getElementById('test').src="include"+incNum+".htm";}
else{alert('the child window has not loaded yet or'+'\n'+'it does not have an iframe with id of test');
}
}
//-->
</script>
</head>
<body>
<input type=button value=doit onclick="winOp(1);">
<p>index 1</p>
<p>&nbsp;</p>
</p>
</body>
</html>

----------------

Was I right to put the script in the <head> area?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum