How do I access the DOM outside of my game

Get help using Construct 2

Post » Sat Jun 13, 2015 5:38 am

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 :?:
B
12
S
2
Posts: 39
Reputation: 1,082

Post » Thu Jun 18, 2015 12:05 pm

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 :).

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.
B
12
S
2
Posts: 39
Reputation: 1,082

Post » Wed Jul 01, 2015 11:38 am

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
B
3
Posts: 3
Reputation: 189

Post » Thu Jul 09, 2015 3:07 pm

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!
B
12
S
2
Posts: 39
Reputation: 1,082

Post » Thu Jul 09, 2015 3:31 pm

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



window.parent.document.getElementById('#MyDiv');
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Thu Jul 09, 2015 4:01 pm

@lennaert

Cheers, probably should have googled it before making that statement :p
B
12
S
2
Posts: 39
Reputation: 1,082

Post » Sun Mar 20, 2016 1:31 am

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?
B
4
Posts: 1
Reputation: 202


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Casimir, plinkie, tarek2 and 11 guests