ULLAS MOHAN.V
ULLAS MOHAN.V

Reputation: 1531

PhoneGap inApp Browser and WebSQL

I got a requirement analysis about PhoneGap InApp Browser.

I want to Know two things about InApp browsers..

1: Can I call an Html file which located in my WWW folder using inApp Browser?

2: Can I create SQLite(WebSQL) and saving data from the Page which loaded in inApp browser? ( Here a page located in WWW folder name test.html and its loading in the inApp Browser. In this html file i coded for create a WebsQL and save data in to Database. is it possible?)

Please tell me about your opinion..

Upvotes: 1

Views: 284

Answers (2)

AtanuCSE
AtanuCSE

Reputation: 8940

  1. Yes you can call local page using

    window.open('mypage.html', '_blank','location=no');

  2. Tricky answer. Yes you can create websql from that page inside inAppBrowser. how! search phonegap/cordova documentation. But... there is an issue using websql in inAppBrowser. Issue explained here : inAppbrowser and webSql failure - cordova

Issue described here : look at the answer

My suggestion wil be use this : SQLite wrapper

Upvotes: 1

islanddave
islanddave

Reputation: 356

1: Yes, you can open an HTML file in your local www folder.

window.open('local-url.html', '_blank');

See this link

2: Yes, there is a way to do it, though not through a formal API. TJ VanToll has a full example available which uses a timeout to check for a value in the web page and then saves it to localStorage. You could then save it to your WebSQL.

<div data-role="view">
    <div>
        <h1>Welcome!</h1>
        <button data-role="button" data-click="app.setName">Set Name</button>
    </div>
</div>
<script>
    window.app = {
        load: function() {
            navigator.splashscreen.hide();
            new kendo.mobile.Application( document.body );
        },

        setName: function() {
            var win = window.open( "http://jsfiddle.net/tj_vantoll/K2yqc/show", "_blank",
                "EnableViewPortScale=yes" );

            win.addEventListener( "loadstop", function() {
                win.executeScript({ code: "localStorage.setItem( 'name', '' );" });
                var loop = setInterval(function() {
                    win.executeScript(
                        {
                            code: "localStorage.getItem( 'name' )"
                        },
                        function( values ) {
                            var name = values[ 0 ];
                            if ( name ) {
                                clearInterval( loop );
                                win.close();
                                $( "h1" ).html( "Welcome " + name + "!" );
                            }
                        }
                    );
                });
            });
        }
    };

    document.addEventListener( "deviceready", app.load );
</script>

And on the local web page, he includes:

$( "form" ).on( "submit", function() {
    localStorage.setItem( "name", this.name.value );
});

Upvotes: 1

Related Questions