SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing code from one frame to another

    I'm having a problem. I'm using frames(yes, I know they're bad but they're useful in this instance) and I need to load one page, then when I load the second page with the content I need to pass along(in the query line most likely) some of the html code from the first page. how do I do this with javascript?

    I'm a bit new to js, so I don't really understand it all yet. Is there a way to like, put all the html between two tags into the query line?

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You can't put the HTML in the querystring (well, you can, but it's not the best way to do things). What you can do is call the frame, grab the HTML in a javascript variable, and enter it on your page. Imagine two pages in a frame. NOTE: be sure to call the frames "left" and "right":
    left.html
    Code:
    <div id="left1">
    <ul>
    <li>List Item</li>
    <li>List Item</li>
    <li>List Item</li>
    <li>List Item</li>
    <li>List Item</li>
    </ul>
    </div>
    right.html
    Code:
    <div id="right1">
    <p>Waiting for the List!</p>
    </div>
    <div id="right2">
    
    </div>
    Now imagine you wanted to grab everything inside the div in left.html and put it in right.html. You can do it like this (put this javascript in the right frame page):
    Code:
    <script type="text/javascript">
    function grabHtml() {
    var theList = left.document.getElementById("left1" ).innerHTML;
    document.getElementById("right1" ).innerHTML = theList;
    }
    </script>
    You can then call the function like so:
    Code:
    <input type="button" onclick="grabHtml();" value="Get the List!">
    The onclick attribute can be assigned to other elements too, like <a> tags.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried that and it doesn't seem to be working. here's the HTML for the 3 pages:

    Code:
    test.php
     
    <html>
    <head><title>test</title></head>
    <frameset cols="50%,*">
       <frame src="left.php" name="left">
       <frame src="right.php" name="right">
    </frameset>
    </html>
    Code:
    left.php
     
    <html>
    <body>
     <div id="left1">
      <ul>
      <li>List Item</li>
      <li>List Item</li>
      <li>List Item</li>
      <li>List Item</li>
      <li>List Item</li>
      </ul>
     </div>
    </body>
    </html>
    Code:
    right.php
     
    <script type="text/javascript">
     function grabHtml() {
      var theList = left.document.getElementById("left1").innerHTML;
      document.getElementById("right1").innerHTML = theList;
     }
    </script>
    <html>
    <body>
     <div id="right1">
      <p>Waiting for the List!</p>
     </div>
     <div id="right2">
      
     </div>
     <input type="button" onclick="grabHtml();" value="Get the List!">
    </body>
    </html>


Bookmarks

Posting Permissions

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