The problem is that I am initially in the function:

// Update DOM on a Received Event receivedEvent: function(id) { var iduserpush = 'no'; alert('iduserpush =' + iduserpush); window.plugins.OneSignal.init( "*******************************", { googleProjectNumber: "*************" }, app.notificationOpenedCallback ); window.plugins.OneSignal.getIds(function(ids) { window.iduserpush = ids.userId; }); ref = cordova.InAppBrowser.open('http://test.ru/index.php?userpush=' + iduserpush, '_blank', 'location=no'); window.open = ref; } 

This is part of the code. Initially, I am in receivedEvent: function(id) { .
I'm trying to create a variable iduserpush .
alert displays the variable correctly, i.e. iduserpush = no .
Next, the script is executed. We get to window.plugins.OneSignal.getIds(function(ids) { .
Here I am trying to catch the value of ids.userId .
Inside the function, everything is fine, but then I try to collect ref , in which iduserpush is mentioned.
Unfortunately, no .

    1 answer 1

    The function passed to window.plugins.OneSignal.getIds is called asynchronously, after the code with ref = ... executed.
    Transfer this code inside the function:

     window.plugins.OneSignal.getIds(function(ids) { iduserpush = ids.userId; ref = cordova.InAppBrowser.open('http://test.ru/index.php?userpush=' + iduserpush, '_blank', 'location=no'); window.open = ref; }); 

    I also replaced iduserpush with iduserpush because they are two different variables.