1

How can I register a function to window (global scope) from within a require.js module?

Background: Cordova / PhoneGap triggers an event to the window.handleOpenURL(url) function in case of opening the app from another app.

Without require.js, just defining the function in the global scope worked fine:

    function handleOpenURL(url) {
    ...
    }

Any ideas?

1 Answer 1

1

Just do like this:

define([], function() {
    window.handleOpenURL = function(url) {
        // code goes here.
    };
});
1
  • Remeber it is only available after the module has been loaded.
    – thetrompf
    May 9, 2016 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.