Search Unity

Is there any way to make Application.OpenURL spawn a new tab or window in WebGL?

Discussion in 'Web' started by crushforth, Nov 4, 2015.

  1. crushforth

    crushforth

    Joined:
    Jul 22, 2010
    Posts:
    113
    I tried this in Unity5.2 and it was causing a crash then I noticed the crash was fixed in Unity 5.3. I've just tried it the latest beta and it works but I was hoping it wouldn't replace the current contents of the browser.

    Is there a workaround for this? Maybe call some javascript of something?

    We're planning on spawning youtube videos because we're having some issues playing videos using the normal normal WebGL method of copying the contents of a hidden video to a texture2D. This method is working perfectly on every machine & platform we've tried it on except the clients Windows 7 machine on both chrome & firefox.
     
  2. heroichippo1

    heroichippo1

    Joined:
    Mar 30, 2015
    Posts:
    36
    Dont use Application.OpenUrl (it uses javascript to call document.url) instead use this...

    Code (CSharp):
    1. Application.ExternalEval("window.open(" + url + ");");
    It will open in a new tab.
     
    Meltdown likes this.
  3. crushforth

    crushforth

    Joined:
    Jul 22, 2010
    Posts:
    113
    Perfect. Thank you.
     
  4. lordubik

    lordubik

    Joined:
    Feb 18, 2013
    Posts:
    149
    There is the way to open an another panel, if enabled a popup-blocker?

    Thanks!
     
  5. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    It's difficult.

    The way most popup-blockers work is that they only allow pop-ups in direct response to user input events.

    Now, the problem is that due to the way input is processed in Unity's main loop, when you receive an input event in Unity, this is already too late to qualify as a "direct user response" (Compare http://docs.unity3d.com/Manual/webgl-cursorfullscreen.html which documents the same issue).

    A solution can be to install an even handler on the mouseUp event in JavaScript, which would open the web page, which you can previously set up when receiving a mouse down event in Unity.