Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Call to page and load IFRAME

    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

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Code:
    <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
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much, I will play around with it.

  • #4
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Which part do i edit to get it to open in the same window?

    Also, which part tells which include # to use?
    Last edited by dsirois1; 10-29-2006 at 04:19 PM.

  • #5
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"+incN um+".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?
    Last edited by dsirois1; 10-29-2006 at 04:47 PM.

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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:
    Code:
    <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:
    Code:
    <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.
    Last edited by brandonH; 10-29-2006 at 07:45 PM. Reason: adding comments
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #7
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"+incN um+".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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •