Jerin Cherian
Jerin Cherian

Reputation: 436

Application.OpenURL not working in mobile

I am building a page in unity and in one of the page I have two button,when clicked should open an external page in browser. for this I used Application.OpenURL. But nothing happens in the mobile,while in editor it shows "NO aplication is set to open "www.google.com" ".

What should I do ?

Attaching my code below,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WebURLScript : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    public void btnOne()
    {
        Application.OpenURL("www.google.com");
    }

    public void btnTwo()
    {
        Application.OpenURL("www.bing.com");
    }

    // Update is called once per frame
    void Update () {

    }
}

Upvotes: 1

Views: 3346

Answers (2)

Neph
Neph

Reputation: 2001

I just came across the same problem with my WebGL app (Unity 2021.2):

On Windows 10 (Firefox, Edge) and Android 11 (Samsung browser, Chrome) pressing a button that calls a function with Application.OpenURL opens a new tab, as expected. On iOS (16.3.1, tested with Safari, Firefox, Chrome) the button would show the "you pressed me" animation but the new page never actually opened.

Chrome eventually showed an "a pop-up was blocked" message and that was the actual problem: All of the browsers mentioned above block pop-ups by default but while Android and Win 10 don't see Unity's Application.OpenURL as a problem, iOS does. Once I'd disabled the "block pop-ups" setting for a specific browser in iOS, clicking the button finally opened the link in a new tab in that browser.

I don't know if it's a bug in iOS or Unity or if iOS is simply meant to work like that and I'm aware allowing all pop-ups isn't ideal (Safari still asks you if you want to open it when the setting is disabled) but Unity doesn't officially support WebGL in mobile browsers (source), so at least it works this way.

Upvotes: 0

Sumit Singh
Sumit Singh

Reputation: 92

Use this way Application.OpenURL("https://www.google.com/")

Upvotes: 2

Related Questions