Mcspam16
07-30-2003, 06:14 PM
Ok I want to put javascript games on my site. But usually when u put javascript games on your site I noticed that they automatically appear on the webpage. I want to be able to put a list of games for the visitor to play. And the visitor can click on the game of their choice and then it will load the game. How do i do this?
karayan
07-31-2003, 12:09 AM
I assume that you want to put all game scripts on the same page. One way to do this is to enclose every game script into its own Javascript function. For example:
<script>
<!--- hide
function game1() {
...
}
function game2() {
...
}
Then, on your HTML page you include the linkas as follows:
<a href="" onclick="game1(); return false">Game 1</a>
<a href="" onclick="game2(); return false">Game 2</a>
etc.
Now, if user clicks on the link that says "Game 1" the game1() function is executed, hence the game.
A word of caution: Beware of what these independent game scripts do to the page. The may modify it in ways that kills your links or interacts badly with the other game scripts.
Best bet is to load each game in its own page, and include <a> links to those pages on your main page.
Hope this helps.