Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Application.OpenURL bug fix new tab: how to stay in same tab?

Discussion in 'WebGL' started by vinodlobo, Jun 9, 2021.

  1. vinodlobo

    vinodlobo

    Joined:
    Dec 3, 2019
    Posts:
    10
    The bug fix that changed the behavior of this function from opening the URL in the same tab to opening in a new tab broke our webgl app: we had an exit url to a different website which integrated our educational app into theirs. We need to stay within the same tab when we pass to this site.

    Is there a way to open a new url and stay in the same tab as before? Surprised that this is not an argument or option, that the bug fix switched behavior from one to another. Thanks for any help on this.

    - Vinod
     
    Chris-KillerSnails likes this.
  2. vinodlobo

    vinodlobo

    Joined:
    Dec 3, 2019
    Posts:
    10
    For reference, this is the bug that was fixed: https://issuetracker.unity3d.com/issues/application-dot-openurl-not-working-for-webgl-builds
    Within the framework.js, this changed window.open second paramater to "_build" instead of "_self". This changes behavior for any project that used this function, and does not give a way to get the "_self" same tab behavior. If the call gave an optional second parameter where we could specify "_self" this would resolve the issue.
     
  3. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    555
    You can implement your own OpenURL method
    https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

    Something like:
    Code (JavaScript):
    1. mergeInto(LibraryManager.library, {
    2.   OpenURL: function (url) {
    3.     window.open(Pointer_stringify(url), '_self');
    4.   }
    5. });
    Code (CSharp):
    1.     [DllImport("__Internal")]
    2.     private static extern void OpenURL(string url);
     
  4. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    494
    You can just use my free asset. It gives you the flexibility to open on a new tab or the current tab, among other things.
     
  5. Chris-KillerSnails

    Chris-KillerSnails

    Joined:
    Oct 6, 2017
    Posts:
    4
    Just updated a project and came across this problem. For WebGL, you should be able to change:

    Code (CSharp):
    1. Application.OpenURL(newURL);
    to:

    Code (CSharp):
    1. Application.ExternalEval("window.open('" + newUrl + "','_self')");
     
    sonterminator123 likes this.
  6. mark3141

    mark3141

    Joined:
    Mar 8, 2022
    Posts:
    1
    I don't care that this is depracated and obsolete... It works perfectly and I'm using it!
     
    LoneGoat likes this.
  7. LoneGoat

    LoneGoat

    Joined:
    Dec 16, 2020
    Posts:
    21

    That works perfectly! Thanks.