Cordova Plugin InAppBrowser sample

var inAppBrowserRef;

function showHelp(url) {

    var target = "_blank";

    var options = "location=yes,hidden=yes,beforeload=yes";

    inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);

    inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);

    inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);

    inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);

    inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack);

    inAppBrowserRef.addEventListener('message', messageCallBack);
}

function loadStartCallBack() {

    $('#status-message').text("loading please wait ...");

}

function loadStopCallBack() {

    if (inAppBrowserRef != undefined) {

        inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;}" });

        inAppBrowserRef.executeScript({ code: "\
            var message = 'this is the message';\
            var messageObj = {my_message: message};\
            var stringifiedMessageObj = JSON.stringify(messageObj);\
            webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);"
        });

        $('#status-message').text("");

        inAppBrowserRef.show();
    }

}

function loadErrorCallBack(params) {

    $('#status-message').text("");

    var scriptErrorMesssage =
       "alert('Sorry we cannot open that page. Message from the server is : "
       + params.message + "');"

    inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);

    inAppBrowserRef.close();

    inAppBrowserRef = undefined;

}

function executeScriptCallBack(params) {

    if (params[0] == null) {

        $('#status-message').text(
           "Sorry we couldn't open that page. Message from the server is : '"
           + params.message + "'");
    }

}

function beforeloadCallBack(params, callback) {

    if (params.url.startsWith("http://www.example.com/")) {

        // Load this URL in the inAppBrowser.
        callback(params.url);
    } else {

        // The callback is not invoked, so the page will not be loaded.
        $('#status-message').text("This browser only opens pages on http://www.example.com/");
    }

}

function messageCallBack(params){
    $('#status-message').text("message received: "+params.data.my_message);
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
cordova-plugin-inappbrowser.inappbrowser cordova cordova-plugin-inappbrowser install cordova-plugin-inappbrowser cordova plugin add cordova-plugin-inappbrowser cordova-plugin-inappbrowser in cordova cordova plugin inAppReviewPlugin cordova-plugin-inappbrowser browser.on cordova plugin inappbrowser alternative cordova plugin inappbrowser browser update cordova plugin add cordova-plugin-inapp-review cordova-plugin-inappbrowser wkwebview cordova-plugin-inappbrowser example cordova-plugin-inappbrowser better options cordova inappbrowser plugin cordova plugin inappbrowser install inappbrowser plugin cordova inapp browser Cordova plugin cordova-plugin-inappbrowser cordova example in-app-browser native cordova plugin cordova inappbrowser plugin example InAppBrowser Cordova Plugin how to use plugin in cordova ionic "window.cordova.plugins.InAppBrowser" android cordova-plugin-inappbrowser system browser in-app browser close how to use cordova plugin in ionic 4 call a plugin inside cordova www call a plugin cordova.js create cordova plugin InAppBrowser on app load in app browser ionic github cordova plugin for browswer cordova-plugin-inappbrowser does not show close button ionic cordova-plugin-inappbrowser cordova plugin add androidx androidx in cordova plugin cordova plugin add cordova-plugin-androidx-adapter cordova enable plugin cordova plugin add cordova-plugin-androidx install inappbrowser plugin cordova with capcitor cordova.InAppBrowser.open cordova inappbrowser close javascript close inappbrowser cordova inappbrowser cordova plugin in app browser ionic inappbrowser load inappbrowser cordova cordova InAppBrowser
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source