Results 1 to 5 of 5

Thread: Javascript: Sending strings to another window

  1. #1

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545

    Javascript: Sending strings to another window

    Hi,

    I'm trying to develop a checker game animator for my checkers website.

    I am trying to do this in the best way possible, which means I don't want to create one html page for each game I wish to animate on my website (that would be much easier for me, but take up too much space). I want to have one animator html page, and then send the game details to a javascript function on this page. Is this possible?

    So basically I want to
    a) From a checker problems page (problems.html) have a list of problems which have links to the animator page (animator.html)
    b) When one of these links are clicked, the game 'details' are passed to a javascript function (loadgame()) on the animator page which is used to animate the game

    Note, I'm not interested in 'how' to animate a game, just the details in how you can transfer data between pages like this.

    Thanks in advance!

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Here is how you can send data from one page to another:
    lets say we want to send the string "Sid is a great man" to page 2, we do this
    var string = "Sid is a great man"
    document.location = "page2.html?string=" + string

    then page two can read the string as follows:
    Code:
    <input type="hidden" name="MyHidden">
    <script language="JavaScript">
    document.getElementById('MyHiddden').value = document.location
    if (document.getElementById('MyHiddden').value.search('string=') != -1)
      {
      var string = document.getElementById('MyHiddden').value.substring(document.getElementById('MyHiddden').value.search('string='),document.getElementById('MyHiddden').value.length)
      alert(string)
      }
    </script>
    Note. I have NOT tried this code out. tell me if there are errors.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    window.open returns a window object. You can use this to call functions in the new window, as well as set variables there.
    From the opened window, you can use the window.opener property to do the same with the parent.
    Finally, frames can communicate via the window.frames and window.parent properties.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    I decided to change my approach to this.

    Rather than sending the entire game string, I am just going to send a 'gameID' instead. I will have a different file for each gameID. So, what I would like to do is include the javascript file for that gameID after loading the animator.html page.

    Here's my HTML code for the animator.html page (Note that I'd like to replace "game00001.js" with a variable, but is this possible?)
    VB Code:
    1. <HTML>
    2. <BODY>
    3. // Load the game based on its game ID
    4. <SCRIPT language="javascript" src="game00001.js"></SCRIPT>
    5. // Load the animator code
    6. <SCRIPT language="javascript" src="animator.js"></SCRIPT>
    7. // Draw the board and navigation buttons
    8. <SCRIPT language="javascript" src="drawboard.js"></SCRIPT>
    9. </BODY>
    10. </HTML>

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You can use document.write to write the script tag...

    Or a server-side scripting langauge.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width