How to embed a Construct 2 project into your website.

You're viewing a single comment in a conversation. View all the comments
  • 2 Comments

  • Order by
  • I have my game embedded in an iFrame on a PARENT webpage and I need to get a variable from the PARENT webpage into my construct game that lives inside an iFrame on the PARENT webpage? I need to SET a Construct Global Variable Value with the value of a variable located in the PARENT Window?

    • A simple solution could be to add a query parameter to the game page url/src of the iFrame, then use C3 to pick up that query parameter with the Browser object (See, en.wikipedia.org/wiki/Query_string).

      For example, http...my-website.com/my-game.html?variable_name=some_value

      However, if the variable is not present when the url is created. You may have to use postMessages to communicate information between the iframe and the parent page (See, developer.mozilla.org/en-US/docs/Web/API/Window/postMessage).

      Alternatively, data can be passed via other intermediaries such as iFrame element attributes, LocalStroage/IndexDB, AJAX requests.