Browser execute external js files

  • If I create an external js file, and execute that file at the start of a layout instead of placing that script into the index.html, will that script respond to javascript function calls I also execute via the browser object?

    Basically does that script continue running, or is it just at time of execution?

  • if you execute it on start of layout it only triggers once,but if you import the js file then access whatever js you want you can execute the file anytime.

    On start of layout import filename.js
    on button click 
             browser execute showpopup()
    [/code:34luij75]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Alright, thanks for the information.

  • There is a difference.

    Here are the ways to run a javascript file other than putting it in script tags. Note that "import" isn't available in older javascript engines.

    https://stackoverflow.com/questions/950 ... cript-file

    As long as you load from a file they will mostly behave the same, although if the load is done via the execute javascript action the file will load asynchronously so it won't be able to run right away.

    If you put code directly in the action that you want to run later, you'll run into scope issues. Basically any var or function will be local instead of global as when run from a file. You can get around that by putting them inside a global variable. For example instead of

    var foo=33;

    you could use

    window.foo=33;

    Then you can use foo any time later.

    Of course in nwjs exports there is no global window object so you'll have to get the global object some other way. Isn't javascript fun?

  • Yeah, it's all fun.

    I'm using an engine where the export is only guaranteed on a platform that's almost impossible to monitise, so they have to wrap it using a seperate api to use on some other platform. All to keep from having to use code, which seems pretty ironic right now.

  • There is a difference.

    Here are the ways to run a javascript file other than putting it in script tags. Note that "import" isn't available in older javascript engines.

    https://stackoverflow.com/questions/950 ... cript-file

    As long as you load from a file they will mostly behave the same, although if the load is done via the execute javascript action the file will load asynchronously so it won't be able to run right away.

    If you put code directly in the action that you want to run later, you'll run into scope issues. Basically any var or function will be local instead of global as when run from a file. You can get around that by putting them inside a global variable. For example instead of

    var foo=33;

    you could use

    window.foo=33;

    Then you can use foo any time later.

    Of course in nwjs exports there is no global window object so you'll have to get the global object some other way. Isn't javascript fun?

    i was referring to plugin-import-previously-quot-css-import-quot_t78007

  • newt what engine would that be,if you don't mind me asking?

  • This one.

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