You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by Apache Wiki <wi...@apache.org> on 2012/11/21 20:33:17 UTC

[Cordova Wiki] Update of "InAppBrowserTest" by ShazronAbdullah

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cordova Wiki" for change notification.

The "InAppBrowserTest" page has been changed by ShazronAbdullah:
http://wiki.apache.org/cordova/InAppBrowserTest

Comment:
added test code

New page:
{{{#!highlight html
       <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>
}}}