Can webpage call Javascript code generated by Cocos Creator?

I followed through the tutorial game for Cocos Creator, and once I was finished I decided to see if I could call external Javascript code from my game. I was able to call the alert() Javascript function successfully.

I’m now wondering if this works the other way around. Is there a way to call a function in my game from the webpage containing the game?

I think we can, but not directly. May be some code like this works:

in Cocos JS:
window.myFunction = function() {...}

in web:

if (window.myFunction) {
    window.myFunction();
}
1 Like

Thank you! This worked for me.