How do I pass config info to C2 web app on startup?

0 favourites
  • 3 posts
From the Asset Store
Create your own casino app and import it to Google Play and the App Store.
  • I have built a web app called ChemThink in C2 which resides on my website, http://www.simbucket.com.

    1. I would like to place different instances of the ChemThink web app in frames in different locations on my website.

    2. Each instance needs to be aware of its parent page so that it loads up the appropriate portion of the web app.

    URL to the ChemThink web app: http://simbucket.com/chemthinkserver/chemthink/

    URL to the simbucket.com parent pages: https://www.simbucket.com/welcome-to-simbucket/

    Depending on which simulation a student clicks on the parent page, I want "ChemThink", the C2 app, to automatically bring the student to the right tutorial or question set upon login.

    Rationale:

    By the time ChemThink is finished, it will be around 8500 events, with hundreds of event sheets. I want to make sure that I don't have to maintain many different versions of the project.

    How do I either do either of the following:

    A. Pass a variable from the parent page to the ChemThink instance so that ChemThink knows which tutorial to load?

    -or-

    B. Give the ChemThink instance the ability to inspect its parent page so that ChemThink knows which tutorial to load?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • How do I either do either of the following:

    A. Pass a variable from the parent page to the ChemThink instance so that ChemThink knows which tutorial to load?

    -or-

    B. Give the ChemThink instance the ability to inspect its parent page so that ChemThink knows which tutorial to load?

    Solved!

    In order to do "B" above, I can get the desired result with the execJS function, as follows:

    1. Create a global variable in the parent page called "tutorialname"

    <script>
          var tutorialname = "";[/code:1w5u1w0h]
    
    2. In Construct, On Start of Layout -> Browser -> Alert Browser.ExecJS("parent.tutorialname")
    
    The bottom line is that I can set a Construct variable = Browser.ExecJS("parent.variablename").  I just need to have the ability to add a variable the parent page's source code.
  • Another approach is to place the variable in a URL query string:

    https://www.mywebsite.com/index.html?ms

    In the event sheet, one can recover the value "ms" as follows:

    On start of layout -> Browser -> Alert tokenat(Browser.ExecJS("window.location.href"),1,"?")

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