# WebView in WebGL

**URL:** https://discussions.unity.com/t/webview-in-webgl/658241
**Category:** Web
**Created:** [March 14, 2017, 12:57pm UTC](https://discussions.unity.com/t/webview-in-webgl/658241 "2017-03-14T12:57:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![aravind07](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@aravind07](https://discussions.unity.com/u/aravind07)
#### Post date: [March 14, 2017, 12:57pm UTC](https://discussions.unity.com/t/webview-in-webgl/658241/1 "2017-03-14T12:57:29Z")

</div>

Hi ,  
In My new Project i would like to add a web view in a WEBGL build … is it possible ? i am using unity version 5.5 … if its possible what all plugins do i need ?

---

<div class="post-metadata">

### Author: ![Schneider21](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/schneider21/32/965781_2.png) [@Schneider21](https://discussions.unity.com/u/Schneider21)
#### Post date: [March 16, 2017, 3:25am UTC](https://discussions.unity.com/t/webview-in-webgl/658241/2 "2017-03-16T03:25:03Z")

</div>

Wait, isn’t the point of a web view to… view a web page? And a WebGL build runs on a web page, so… you want to have a web page inside an applet inside a web page?

---

<div class="post-metadata">

### Author: ![BaiboZhang](https://avatars.discourse-cdn.com/v4/letter/b/51bf81/32.png) [@BaiboZhang](https://discussions.unity.com/u/BaiboZhang)
#### Post date: [July 19, 2017, 8:31am UTC](https://discussions.unity.com/t/webview-in-webgl/658241/3 "2017-07-19T08:31:42Z")

</div>

Uniwebview can be used for mobile platforms. But how can I show a webview in WebGL ? I means to show some web page in a WebGL app.

---

<div class="post-metadata">

### Author: ![ammarvohra](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/ammarvohra/32/932239_2.png) [@ammarvohra](https://discussions.unity.com/u/ammarvohra)
#### Post date: [September 28, 2017, 7:24am UTC](https://discussions.unity.com/t/webview-in-webgl/658241/4 "2017-09-28T07:24:11Z")

</div>

You can call the external jslib method to open iframe for your perticular website. For example  
I added this example.jslib in _Plugins_ folder

```javascript
var IframePlugin = {
      iframeClick: function() {
        if (!document.getElementById('webview')) {
          var ifrm = document.createElement("iframe");
          ifrm.setAttribute("src", "https://www.someexample.com");
          ifrm.setAttribute("id", "webview");
          ifrm.style.width = "640px";
          ifrm.style.height = "480px";
          document.body.appendChild(ifrm);
        }
      }
    };
    mergeInto(LibraryManager.library, IframePlugin);

```

and called it from _C#_ script using:

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;

public class tempscript : MonoBehaviour
{

    [DllImport("__Internal")]
    private static extern void iframeClick();

    public void OpenWebView()
    {
        iframeClick();
     }

}

```

**NOTE:** You need to add the UI button with the component _EventTrigger_ and adding _OnPointerDown_ method to call the _OpenWebView()_ method. Also you cannot open some sites which have limitations of access control like _google, facebook, yahoo, etc._

---

<div class="post-metadata">

### Author: ![nsmith1024](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@nsmith1024](https://discussions.unity.com/u/nsmith1024)
#### Post date: [July 13, 2019, 3:29pm UTC](https://discussions.unity.com/t/webview-in-webgl/658241/5 "2019-07-13T15:29:04Z")

</div>

anybody tried this, does it actually show a webpage inside WebGL?

---

<div class="post-metadata">

### Author: ![Parixit\_Jadeja](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Parixit\_Jadeja](https://discussions.unity.com/u/Parixit_Jadeja)
#### Post date: [August 25, 2020, 3:24pm UTC](https://discussions.unity.com/t/webview-in-webgl/658241/6 "2020-08-25T15:24:00Z")

</div>

I have tested this and it is working. A web-view window opens behind the WebGL window. But, I think we can work on looks by changing the unity template and example.jslib.

---

<div class="post-metadata">

### Author: ![Parixit\_Jadeja](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Parixit\_Jadeja](https://discussions.unity.com/u/Parixit_Jadeja)
#### Post date: [August 25, 2020, 5:23pm UTC](https://discussions.unity.com/t/webview-in-webgl/658241/7 "2020-08-25T17:23:42Z")

</div>

This is how it looks:

 ![6243140--687605--upload_2020-8-25_22-47-14.jpg](https://europe1.discourse-cdn.com/unity/original/3X/7/3/735af5bb3fce9def8d9a18218a750794906bd72b.jpeg)

You can also pass link from unity like this:

```javascript
mergeInto(LibraryManager.library, {
  LoadWebView: function (str) {
    window.alert(Pointer_stringify(str));
    if (!document.getElementById('webview')) {
          var ifrm = document.createElement("iframe");
          ifrm.setAttribute("src",Pointer_stringify(str));
          ifrm.setAttribute("id", "webview");
          ifrm.style.width = "640px";
          ifrm.style.height = "480px";
          document.body.appendChild(ifrm);
    }
  },
});

```

Unity Code:

```csharp
    string url = "https://www.sample.com/";

    // Start is called before the first frame update
    void Start()
    {
        LoadWebView(url);
    }

    [DllImport("__Internal")]
    private static extern void LoadWebView(string url);

```

You can see this link for more information:- [Unity - Manual: Interaction with browser scripting](https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html)
