I am using WeixinJSBridge to modify the sharing parameters when someone shares one of my games (made with JavaScript) using Wechat (Weixin).

The following code, which is at the end of a big JavaScript file (more than 2500 lines, around 100 KB) and outside any function or object, works like a charm and the function WECHAT_onBridgeReady is called as expected when the WeixinJSBridge is ready (using the game in Wechat / Weixin):

if (document.addEventListener)
{
    document.addEventListener('WeixinJSBridgeReady', function() { WECHAT_onBridgeReady(); }, false);
}

But the following code doesn't not (the WECHAT_onBridgeReady is never called):

if (document.addEventListener)
{
    document.addEventListener('WeixinJSBridgeReady', WECHAT_onBridgeReady, false);
}

I would like to know why there is a difference between passing the funcion as parameter (which doesn't work) and passing an encapsulated function that calls the function (which works).

Here you can see the game (made in 2006, the code is a mess and in Spanish, but I am trying to modify it now to improve it and adapt it to modern mobile devices): http://yasminoku.tuxfamily.org/new/online/ (the JavaScript file is in http://yasminoku.tuxfamily.org/new/online/yasminoku.js)

Both methods worked before for me in another previous game, but the JavaScript file was much tinier (around 8KB) and the code that sets the event listeners was placed in the beginning of that file. This is why I think this issue could have something to do with the time the file needs to be loaded completely and parsed by the JavaScript engine, but I am not sure.

Does anyone know the reason, please?

Thank you in advance.

Cheers, Joan

1

There are 1 answers

0
Lionep On

I think you should define the method WECHAT_onBridgeReady before the script document.addEventListener(...).