gree / unity-webview

zlib License
2.31k stars 696 forks source link

How to dynamically load url ? #398

Open ankursahu19 opened 5 years ago

ankursahu19 commented 5 years ago

Is there any function that will help me for dynamically change url Thanks!

KojiNakamaru commented 5 years ago

You can utilize webViewObject.LoadURL() to load a url:

https://github.com/gree/unity-webview/blob/04e312c4e5d9cbe08ec29fcdbeec7688a41b67aa/sample/Assets/Scripts/SampleWebView.cs#L107

You may also utilize JavaScript through webViewObject.EvaluateJS():

webViewObject.EvaluateJS("location.replace('https://developer.mozilla.org/en-US/docs/Web/API/Location#Methods');")
ashishgaur805 commented 3 years ago

How to dynamically change url ? like enter url on inputfield and on button clicked open webpage.

KojiNakamaru commented 3 years ago

This plugin doesn't provide any UI for address bar, etc. You can create them by uGUI.

ashishgaur805 commented 3 years ago

I have created a textfield and GUI button to open given url but i am not able to enter text in text box here is my code public string txtc; void OnGUI() { txtc = GUI.TextField(new Rect(x, 10, 180, 80), txtc,50); //x += 290;

    if (GUI.Button (new Rect (300, 10, 180, 80), "GO !!")) {
        Debug.Log("<color=yellow> THIS is url </color>"+ txtc);
        webViewObject.LoadURL(txtc);
    }

}

KojiNakamaru commented 3 years ago

I'm sorry, the current implementation for OSX/Editor is incomplete about keyboard event emulation. I would like to fix it in the future, but it will take some time. Your code should work well on iOS/Android devices.

KojiNakamaru commented 3 years ago

I reduced the issue a bit in #739 and updated binaries. Could you please try the latest?

ashishgaur805 commented 3 years ago

Thanks for your reply @KojiNakamaru I have made some changes on sample.html and it is working for me on Unity App.

Enter Your URL Here
Click Here !!!

Screenshot 2021-09-27 at 11 18 09 PM