jj.
jj.

Reputation: 13

Start a flash game when the user clicks

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?

Upvotes: 1

Views: 144

Answers (1)

easeout
easeout

Reputation: 8734

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.

Upvotes: 2

Related Questions