[Solved][WebPlayer] Opening new tab using a button and focus issues

Hi there ^^

So here’s my problem, i have a webplayer / webGL project, where i can open new tabs clicking on a button. But when i do, the button is stuck in “pressed mode” (unless i go back to my game tab and click anywhere on the screen), and when i click on the new tab opened, the tab keeps opening again, as if the button still is selected and intercept the mouse click.

So, i looked a bit in the UI Button documentation, but didn’t find how to break the focus on the button, when i click on it so that i can avoid this issue.

Do you have any idea how to do this ?

Thank you for reading :slight_smile:

Ok so i managed to fix this doing the following things:

  • i added 2 functions in the php page hosting the game using jquery:
$(window).focus(function()
{
    console.log("we have focus");
  
    var unityObj = retrieveUnityObj();
  
    if(unityObj != undefined && unityObj != null)
    {
        //allow to open links
        retrieveUnityObj().SendMessage("AnswerSheetScreen", "AllowToOpenLink", "");
    }
});

$(window).blur(function()
{
    console.log("WE LOST FOCUS");
  
    var unityObj = retrieveUnityObj();
  
    if(unityObj != undefined && unityObj != null)
    {
        //block links
        retrieveUnityObj().SendMessage("AnswerSheetScreen", "BlockAnyLinkOpening", "");
    }
});

So that i can detect when the players leaves the current tab, and when he goes back.
It solves the issue.

Also, to get the button out of the “selected state”, i just used this to focus another object:

EventSystem.current.SetSelectedGameObject(_uiText.gameObject);