cookies or no? RRS feed

  • Question

  • Hey guys (and girls),

    I'm having trouble accessing data from an old window in a new window.
    Let me re-phrase this...
    The user of my site needs to click an 'open' button on the page to open a data record. The button opens the record in a new window. This is where the problem is, I need to get the information off of the initial page and use it in the new window.

    I've tried cookies, and that is not working.. here is what i did when i tried using cookies, maybe it's something simple that i'm not doing right (i'm new to this whole web programming thing)...

    This is when i set the cookie...

      <form id="form1" name="form1" method="post" action="log.php">
       <select name="notes" size="5" id="notes">
       <?php fill_notes($id); ?>
       </select><br />
       <input name="add_note" type="submit" id="add_note" value="Add" />
       <textarea rows="2" name="add_note_text" cols="50"></textarea>
       <br />
       <input name="edit_note" type="submit" id="edit_note" value="Edit" />
       <textarea rows="2" name="edit_note_text" cols="50"></textarea>
       <br />
       <input name="delete_note" type="submit" id="delete_note" value="Delete" />
       <br />
       <input name="open_note" type="button" id="open_note" value="Open" onclick=
        <?php setcookie("message", $_POST["notes"], time() + 86400); ?>"open_notes()" />

    This is where i open the new window...


     <script type="text/javascript">
      // Function:  open_notes()
      // Parameters: none
      // Returns:  none
      // Description: opens a note in the user's list in a full popup window
      function open_notes()
       //Get the message
       var message = document.getElementById("notes").value;
       //Open the note in a new simple popup window
       window.open("message.php", "winlink", "height=400, width=800");


    And this is where I try to get the data in the cookie in the new window...

    <html xmlns="http://www.w3.org/1999/xhtml">
     <title>Message Viewer</title>

       $message = $_COOKIE["message"];
       echo '$message';
       print("Sorry, an error has occured...");        //THIS ALWAYS PRINTS...


    Any insight would be greatly appreciated.
    If you need more background info, just let me know..

    Thanks again!

    Wednesday, December 6, 2006 3:57 AM


  • You can do this completely through javascript, bypassing cookies altogether, using the window.opener property to reference the original window and use the DOM to access the elements and their values on that page. 

    See: http://www.w3schools.com/htmldom/dom_obj_window.asp for more info on the DOM and how to get what you want from the original page.

    Wednesday, December 6, 2006 8:01 AM