How do I access the DOM outside of my game

0 favourites
  • 7 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I'm using Laravel to build a website with Construct 2

    Laravel supplies CSRF tokens when posting forms and I'd like to keep it that way!

    I need a safe way to access the CSRF token from within my construct 2 application so that I can post data via AJAX.

    I need to access the DOM outside of my games environment so that I can access this CSRF token from a hidden form element. If anyone can think of a better, cleaner and safe way of doing this, then that too would be awesome!

    If there's nothing available, perhaps I could make a small plug-in? Would plug-ins allow me to access the DOM

  • I figured it out by making a plugin as mentioned here:

    https://www.scirra.com/manual/22/runtime-overview

    If anyone comes across a similar problem, let me know and I'll post some instructions <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">.

    btw, the sdk was plain awesome! So easy to follow. I expected to have to spend days studying but had something whipped up in a couple of hours.

  • I have a similar problem: I want to pass a string to a div outside my game.

    I figure I can do this with the Execute Javascript expression, but I guess the correct way of doing it (putting aside all the problems of accessing stuff outside the c2 canvas) is through a plugin.

    If you have anything to share on how you did the basics, that would mean a lot.

    Thanks

  • When I get the chance, I'll write a simple plugin. It wouldn't be too hard, I should be able to just map some jquery commands like .html() .attr() etc.

    Will probably run into problems accessing elements outside of an iFrame though!

  • Will probably run into problems accessing elements outside of an iFrame though!

    window.parent.document.getElementById('#MyDiv');

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • lennaert

    Cheers, probably should have googled it before making that statement :p

  • Hi, I have the same problem and found this thread and wonder if you can help.

    I have my game on my subdomain, which is then loaded in an iframe on a page on the main domain. I am not sure if this a an issue.

    I am trying to change the display of a section (Id:next) on the page. I am using Browser>Execute Javascript with the code

    "window.parent.document.getElementById('next').style.display = 'block';"

    which does not work.

    How can I make this work?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)