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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I rewrite the contents of one frame from another?

    This might be a stupid question, but...

    If I have a page split into two frames, how might I rewrite the text in one frame by clicking a link on the other? It looks like this:

    <head>
    var Text = "I am text!"
    var Text2 = "I am some different text!"
    </head>
    <body>
    <a href = "#" onClick = "Top.OtherFrame.document.write(Text);">Link 1</a>
    <a href = "#" onClick = "Top.OtherFrame.document.write(Text2);">Link 2</a>
    </body>

    The problem, of course, is that when either link is clinked, it adds text to the text that's already there. I only want the contents of one variable to be visible.

    Please help me! It would be much appreciated.

  • #2
    JUD
    JUD is offline
    New Coder
    Join Date
    Jul 2005
    Location
    I'm right here
    Posts
    92
    Thanks
    0
    Thanked 2 Times in 2 Posts
    When writing to another frame you need to open and close streaming to the frames document. You do this with document.open() and document.close().

    You also need to put you variables between opening and closing <script> tags.

    Here's an example:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    >
    <
    html>
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    title>Untitled Document</title>
    <
    script language="javascript" type="text/javascript">
    var 
    Text1 "I am the text for link 1";
    var 
    Text2 "I am the text for link 2";
    </script>
    </head>

    <body>
    <a href="#" onClick="top.frames['otherFrame'].document.open();top.frames['otherFrame'].document.write(Text1);top.frames['otherFrame'].document.close()">Link 1</a><br>
    <a href="#" onClick="top.frames['otherFrame'].document.open();top.frames['otherFrame'].document.write(Text2);top.frames['otherFrame'].document.close()">Link 2</a>
    </body>
    </html> 
    Hope that helps
    JUD
    Last edited by JUD; 12-31-2005 at 04:37 PM.

  • #3
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank you!!!

    Yes! It works! It finally works! Thank you so much! ^___^


  •  

    Posting Permissions

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