My iframe application on Facebook (made with Unity webgl) loses focus after calling Facebook Login dialog (FB.LogInWithReadPermissions), or any other interaction with Facebook which brings up dialog window (FB.AppRequest etc).
Focus is not returned to the application, so you need to click anywhere on the iframe to see the results, which is not very convenient.
Any workaround?
Edit:
Quick and dirty solution, but it works:
setInterval (
function () {
if (!document.hasFocus()) {
window.focus();
}
},
1000
);
Actually document.hasFocus()
check is not needed here.
I don't think there is a way to know when Facebook dialog window closes while using Facebok Unity SDK, since the callback is executed in WebGL application which lost focus, so it doesn't work until it actually gains focus.
Maybe it's better to use Facebook Javascript SDK for Unity WebGL games on Facebook?
I had a similar issue quite some time ago. I solved it by adding one listener function to index.html. It would listen if the iframe lost focus and hard reset the focus on it. Have a look at onblur event.