Urgent please! Link to external page inside WebGL doesnt work on Safari

Hi I use this code in Unity:

using UnityEngine;

public class UrlOpenner : MonoBehaviour

{
public string Url;

public void Open()
{
    Application.OpenURL(Url);
}

}

and works great on google/android but doesnt work on safari/iphone

Please is urgent!!

Hey @lreyesreginato

Welcome to the forum.

This question seems more Unity specific than related to our Universal AR SDK, thus we encourage you to post such questions on Unity answers or forum, where you may have faster response to such queries.

That said, Application.OpenURL is subjected to the permissions and limitations of your app’s current platform and environment. Especially for mobile browsers it cannot be used to open local files or will always try to open the webpage in new tab. Here’s a quick webgl plugin that allows you to open URL/resource in the browser (PFA). You should be able to just call Nfynt.NPlugin.OpenURL(url) which will open it in a new tab.

HTH

Best,

NPlugin.zip (1.3 KB)

2 Likes

The question you asked is very good. I read it carefully but could not find anyone to help me understand it. Anyone can describe it correctly here https://forum.zap.works/t/urgent-please-link-to-external-page-inside-webgl-doesnt-nuwaveairfryer-work-on-safari/8981/2

Hello @muellerswag1234

Safari is relatively more strict when compared to Chrome or Firefox, in terms of handling browser permissions. And then there’s limitations of Application.OpenURL API for WebGL which you can read here.

In this case, you may wanna check your Safari settings to make sure Block Pop-ups is disabled for OpenURL API to work. Otherwise you may try opening URL in same tab as following:

#if UNITY_WEBGL && !UNITY_EDITOR
        Nfynt.NPlugin.OpenURLInSameTab(URL);
#else
        Nfynt.NPlugin.OpenURL(URL);
#endif

Couple of other things to check would be:

  • You are calling this method on user input event i.e. touch, click, etc.
  • You are not calling this from async part of your code

Best,

1 Like

Thanks!,

I had the same issue and after applying your code suggestion, I was able to fix the open url problem in Safari.

2 Likes

Hello, I am following the same procedure, but I get build errors. I cannot figure out why? Any tips?
I have added the Nfynt package.
I am calling it like this:

public void OpenURLSameTab(string newURL)
{

#if UNITY_WEBGL && !UNITY_EDITOR
Nfynt.NPlugin.OpenURLInSameTab(newURL);
#else
Nfynt.NPlugin.OpenURL(newURL);
#endif

}

but I’m getting this error:

Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.js: undefined symbol: OpenURL (referenced by top-level compiled C/C++ code)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)

Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.js: undefined symbol: OpenURLInSameTab (referenced by top-level compiled C/C++ code)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)

I tried everything I knew, made a blank project, removed library folder, anything really.

Thank you!

Hello @roozbeh.desire ,

From the error logs, it seems the compiler is unable to locate the function symbols! Can you confirm your project contains the NPlugin.cs under the main project directory and OpenURL.jslib under the Plugins directory?

Best,

Thank you so much! It indeed was an issue with placement of the files. My bad