Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(5 edits) (+1)

Thank you for taking it into account! :-)

You should be done with the following two lines of code:

let frame = document.getElementById('your-iframe-id');
frame.contentWindow.postMessage( 
    /*JavaScript-variable containing the username as string*/, 
    /*itch-io-domain-address*/);

This way the current username is just always thrown via postMessage() into the iframe. The programmer of the game is then free to catch or ignore it. If he wants to catch it, he could do this with the following code:

window.addEventListener('message', event => {
    // IMPORTANT: check the origin of the data!
    if (event.origin.startsWith(/*itch-io-domain-address*/)) {
        // good case:        
        // The data was sent from itch.io.
        // Data sent with postMessage is stored in event.data:
        console.log(event.data); // Would print the username to the console.
    } else {
        // bad case:
        // The data was NOT sent itch.io!
        // Be careful! Do not use it. This else branch is here
        // just for clarity, you usually shouldn't need it.
        return;
    } 
});

I have stolen this idea and the source-code from here. ;-)

Admin(+4)

We would not approach it like this. We would require the user to opt into sharing their information with the game. We would expose it to the game developer as an itch.io JavaScript API where they can make an async request to get information about the current user.

Thanks