0

OK, so here's the rub. I downloaded a ton of SWF games online, and I want to create my own way to use them. I want to create a directory in the main menu of my HTML file that brings me to another menu with a ton of different choices of games. I know how to play them using the embed tag, but I don't want to create 40 different HTML files for each different game. I know there's a way to click any game you want and go to one HTML page, remembering which game you clicked, and play it, I just don't know what it is. I want every game to point to one embed.html page and it play the SWF file that you clicked. Any help would be much appreciated. I'm working on a work-around to play games on our crappy school Chromebooks. I might be overlooking something really simple, but I don't care. This would be amazing to have. Thanks StackOverflow!

1
  • Could you provide some code: showing how you plan to embed the games. Commented Feb 12, 2020 at 2:45

2 Answers 2

1

Changing SRC of <embed> to change file being shown

Here is something you can try. You can have a button for each game, name the button to the game. Then you can have an <embed> item with the src set to a default item. Then using the following JS: document.getElementById("game").src = "game.swf" to change the src of the item to whichever game you would like. Here is an example site I created with two random .swf files I downloaded off the the internet. There is a .swf file and when you click the button the .swf file is changed to a different file:

<html>

<head></head>

<body>
    <button onclick="changeGame()">Click to change</button>
    <embed id="game" src="BannerSnack-ad-336x280.swf" type="">
    <script>
        function changeGame() {
            document.getElementById("game").src = "Car-speakers-590x90.swf"
        }
    </script>
</body>

</html>

You can create a function for each button and game you want to use, this should be the simplest way to do this as I assume you are new to JS. This allows you to have one page with a number of buttons and one <embed> tag to hold the game.

Edit

For your problem it looks like using something like this might help:

<button onclick="clicked()">click</button>

<script>
    function clicked() {
        var opened = window.open("");
        opened.document.write("<html><head><title>Game</title></head><body><embed id=\"game\" src=\"game.swf\" type=\"\"></body></html>");
    }
</script>

This basically uses JS to create a new web page with an embed section. You can create a new function for each game like above. Hope this is what you were looking for.

Sign up to request clarification or add additional context in comments.

8 Comments

Is there a way to open a new page with this information stored or will I have to keep it on the page with the buttons?
What do you mean exactly?
I don't think that this method would work with the way I'm trying to do it. I want to click a game button, use the javascript function to change the source, and open a new page, displaying that game. Could I maybe use cookies?
Yes it was a typo, i was looking into it and then accidentally pressed enter before finishing my comment haha, will edit my answer with a solution in a second
Lol that's fine. Did you have an idea though?
|
1

It sounds like you could either make a new tab with a variable linked to the game you click on or use something like this as a template. It uses JSON object data to load content onto an HTML doc. You can do that with links to each of your games!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.