|
-
Oct 30th, 2003, 02:00 PM
#1
Thread Starter
Frenzied Member
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!
-
Oct 30th, 2003, 02:17 PM
#2
Frenzied Member
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.
-
Oct 30th, 2003, 03:07 PM
#3
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.
-
Nov 6th, 2003, 02:25 AM
#4
Thread Starter
Frenzied Member
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:
<HTML>
<BODY>
// Load the game based on its game ID
<SCRIPT language="javascript" src="game00001.js"></SCRIPT>
// Load the animator code
<SCRIPT language="javascript" src="animator.js"></SCRIPT>
// Draw the board and navigation buttons
<SCRIPT language="javascript" src="drawboard.js"></SCRIPT>
</BODY>
</HTML>
-
Nov 6th, 2003, 03:02 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|