views:

43

answers:

1

I want to put two miniclip.com games in my website but they both start at the same time.
How can I get them to start separately when the user clicks them?

+1  A: 

There are ways to do this with JavaScript. One is to display a link in a div, and have the link's onclick script replace the link itself with the HTML that embeds the game. Then when you click the link, the game loads and displays. For instance:

<div id="game1Container">
    <a href="#" onclick="document.getElementById('game1Container').innerHTML = 'GAME HTML GOES HERE'; return false;">Start the game!</a>
</div>

You would replace the text GAME HTML GOES HERE with your <embed> tag, or whatever it is you're already using to load the game. But, it may not work right unless you take that HTML and encode it properly so that < becomes &lt;, > becomes &gt;, and " becomes &quot;. I see you tagged this question with the "dreamweaver" tag. Dreamweaver probably has such a feature, so look around in there. There are also websites that can do this encoding for you (or, there must be).

Doug Neiner pointed out in a comment: If you want to make it really nice, you can replace Start the game! with an <img> that displays a screenshot of the game, overlaid with some text like "Play". This is like how YouTube displays a screenshot of a video, and you click to start it.

Kevin Conner
Great answer @Kevin. The only thing that might this more seamless is if you used an image thumbnail the same size as the loaded game so it "looks" loaded though it really only loads on click.
Doug Neiner
You can use SWFObject for this click eventhttp://blog.deconcept.com/swfobject/
Harmen
kevin conner u are a bloody genius it works thanks alot!!!!!!!!!!!!!!!!
jj
Thanks! If you accept my answer, would you please click that green check? Welcome to stackoverflow.com :)
Kevin Conner