Welcome! › Forums › Unity Plugins › In-App Web Browser › Back Button In front of page
- This topic has 8 replies, 2 voices, and was last updated 7 years, 1 month ago by Piotr.
-
AuthorPosts
-
July 12, 2017 at 1:12 pm #266ZeldarckParticipant
Hi,
I use the plugin in the goal to do a full screen player of youtube video, (to host the video/subtitle on youtube).
To display the video I use this html:
<div style='position:absolute;left:0;right:0;top:0px;bottom:0;overflow:auto;'><iframe id=\"ytplayer\" type=\"text/html\" width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/kQye2uNafk0?autoplay=1&controls=0&rel=0&showinfo=0&cc_load_policy=1&hl=ru&fs=1\" frameborder=\"0\" style=\"margin:0px;padding:0px;\"/></div>
I would like to display the back button in front of the video (because Iphone don’t have back button :'( ). Is it possible by any mean ? Or I have to create a custom html button wich call a js to close the browser? And for close with js, is it a direct function, or I have to usefunction sendMessageToUnity(message) { if (isIOS()) { appendIframeWithURL('inappbrowserbridge://' + message); } else if (isAndroid()){ UnityInAppBrowser.sendMessageFromJS(message); } }
To call a unity function wich close the Browser?
July 12, 2017 at 2:50 pm #268ZeldarckParticipantOk, I have do that :
<script> var userAgent = navigator.userAgent || navigator.vendor || window.opera; function isIOS() { if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { return true; } else { return false; } } function isAndroid() { return (/android/i.test(userAgent)); } In function sendMessageToUnity(message) { if (isIOS()) { appendIframeWithURL('inappbrowserbridge://' + message); } else if (isAndroid()){ UnityInAppBrowser.sendMessageFromJS(message); } } </script> <div style='position:absolute;left:0;right:0;top:0px;bottom:0;overflow:auto;'> <button type="button" onclick="sendMessageToUnity('message')" style = " border-radius: 8px; border: none; padding: 0em 1em; color: white; font-size: 16px;position: absolute;top: 10px;left: 10px;background-color: #000000;height: 30px;">X</button> <iframe id="ytplayer" type="text/html" width="640" height="360" src="http://www.youtube.com/embed/kQye2uNafk0?autoplay=1&controls=0&rel=0&showinfo=0&cc_load_policy=1&hl=ru&fs=1" frameborder="0" style="margin:0px;padding:0px;"/> </div>
void Start(){ InAppBrowserBridge bridge = FindObjectOfType<InAppBrowserBridge>(); bridge.onJSCallback.AddListener((string s) => OnCloseBrowser()); } public void OnCloseBrowser() { StartCoroutine(CloseYouTubeVideo()); } protected IEnumerator CloseYouTubeVideo() { InAppBrowser.CloseBrowser(); Screen.orientation = ScreenOrientation.Portrait; while (Screen.currentResolution.height > Screen.currentResolution.width) { yield return null; } UICommander.ShowAll(); } protected IEnumerator PlayYoutubeVideo() { yield return new WaitForSeconds(1); UICommander.HideAll(); Screen.orientation = ScreenOrientation.Landscape; while (Screen.currentResolution.height > Screen.currentResolution.width) { yield return null; } InAppBrowser.DisplayOptions displayOption = new InAppBrowser.DisplayOptions(); displayOption.displayURLAsPageTitle = false; displayOption.hidesTopBar = true; InAppBrowser.OpenLocalFile("test.html", displayOption); }
still not very beautiful, if you have a better mean, I’m open to 🙂
- This reply was modified 7 years, 2 months ago by Zeldarck.
July 13, 2017 at 10:28 am #271PiotrKeymasterLooks good 🙂
July 17, 2017 at 9:34 am #291ZeldarckParticipantI will begin the debug, but this code didn’t work on IOS (but very well in android)
July 17, 2017 at 12:32 pm #292ZeldarckParticipantSo, the message is effectivily send with
function sendMessageToUnity(message) { if (isIOS()) { appendIframeWithURL('inappbrowserbridge://' + message); } else if (isAndroid()){ UnityInAppBrowser.sendMessageFromJS(message); } }
but my callback is not call:
bridge.onJSCallback.AddListener((string s) => OnCloseBrowser()); public void OnCloseBrowser() { StartCoroutine(CloseYouTubeVideo()); }
July 17, 2017 at 4:47 pm #293PiotrKeymasterwhat’s
appendIframeWithURL
?July 18, 2017 at 7:38 am #294ZeldarckParticipantOk I am idiot, I forgot to c/c the code of this function from your read me, I will try with, sorry ><
July 18, 2017 at 9:20 am #295ZeldarckParticipantSo it’s work 🙂
July 18, 2017 at 3:37 pm #296PiotrKeymasterCool. btw that Javascript code from readme is just example, I didn’t assume people will actually use it in production 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.