Skip to main content

In iframe

iframe integraion is a fastest way to embed a game on your web page. Open DOS Zone repository and search for game, for example 'Digger'. Then you need to press on code </> button:

Code button

It will open a frame whith html5 code that you need to paste on your website:

Code frame


info

To receive input you should focus the iframe (by click or using js):

iframe.focus();

Iframe example#

Example of web page that uses iframe integration:

examples/iframe.html
Run
{}

Client ID#

iframe intergation also support passing client id. To do this you need to modify iframe src. Replace anonymous=1 with anonymous=0. In that case you need handle auth client request in parent window, like this:

const clientIdListener = async (e: any) => {
if (e.data.message !== "dz-client-id") {
return;
}
const gesture = e.data.gesture;
let user = getLoggedUser();
if (user === null && gesture) {
user = await login();
}
if (user === null) {
iframe.contentWindow?.postMessage({
message: "dz-client-id-response",
}, "*");
} else {
iframe.contentWindow?.postMessage({
message: "dz-client-id-response",
namespace: user.namespace,
id: user.id,
}, "*");
}
};
window.addEventListener("message", clientIdListener);

DOS Zone#

Read more about dos.zone.