Created
November 20, 2012 22:04
-
-
Save shazron/4121555 to your computer and use it in GitHub Desktop.
Testing InAppBrowser for Cordova 2.3.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| if (typeof String.prototype.startsWith != 'function') { | |
| String.prototype.startsWith = function (str){ | |
| return this.slice(0, str.length) == str; | |
| }; | |
| } | |
| function launchUrl() { | |
| try { | |
| var url = document.getElementById("windowUrl").value; | |
| var target = getWindowName(); | |
| var showLocationbar = document.getElementById("windowOptions").checked; | |
| if (!url.startsWith('http://') && !url.startsWith('https://')) { | |
| url = 'http://' + url; | |
| } | |
| window.open(url, target, "location=" + (showLocationbar? "yes":"no")); | |
| } catch (e) { | |
| alert(e); | |
| } | |
| } | |
| function getWindowName() | |
| { | |
| var radioButtons = document.getElementsByName("windowName"); | |
| for (var i = 0; i < radioButtons.length; ++i) { | |
| if (radioButtons[i].checked) { | |
| return radioButtons[i].value; | |
| } | |
| } | |
| } | |
| function checkUrlLength() { | |
| var txt = document.getElementById("windowUrl"); | |
| var btn = document.getElementById("launchButton"); | |
| btn.disabled = (txt.value.length == 0); | |
| } | |
| </script> | |
| <div style="margin-left:10px"> | |
| <div style="margin-top:20px"> | |
| <input type="radio" name="windowName" value="_self" />_self | |
| <input type="radio" name="windowName" value="_blank" checked="checked" />_blank | |
| <input type="radio" name="windowName" value="_system">_system | |
| </div> | |
| <div> | |
| <input type="checkbox" id="windowOptions"/>Show location bar? | |
| </div> | |
| <div> | |
| <input id="windowUrl" placeholder="Enter a url" onkeyup="checkUrlLength()" style="width:80%" type="text" id="windowUrl" value="www.google.com"/> | |
| </div> | |
| <button id="launchButton" onclick="launchUrl()">Launch InAppBrowser</button> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment