Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Events to use with InAppBrowser plugin: Phonegap

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 946
    Comment on it

    In this post, you will see the events that can be used in InAppBrowser plugin.
    There are different methods:

    • addEventListener
    • removeEventListener
    • close
    • show
    • executeScript
    • insertCSS

    InAppBrowser.addEventListener:
    It will add a listener for an event from InAppBrowser.
     

    ref.addEventListener(eventname, callback);

    here ref is reference to InAppBrowser window. eventname can be of these types:

    • loadstart: when URL starts loading.
    • loadstop: when URL stops loading.
    • loaderror: when there is an error while loading URL.
    • exit: when the InAppBrowser window closes.
    • callback: It is a function that is called when any event fires. This function passes an object InAppBrowserEvent as parameter.   

    Example:
     

    var ref = cordova.InAppBrowser.open('http://google.com', '_blank', 'location=yes');
    ref.addEventListener('loadstart', function(event)
     {
    alert(event.url);
    });

    InAppBrowser.removeEventListener:
    It will remove a listener for an event in InAppBrowser.
     

    ref.removeEventListener(eventname, callback);

    The properties are same as addEventListener.

    Example:
     

    var ref = cordova.InAppBrowser.open('http://google.com', '_blank', 'location=yes');
    var CallbackFunc = function(event) { alert(event.url); }
    ref.addEventListener('loadstart', CallbackFunc);
    ref.removeEventListener('loadstart', CallbackFunc);

    InAppBrowser.close:
    It will close the InAppBrowser window.

    ref.close();


    Example:
     

    var ref = cordova.InAppBrowser.open('http://google.com', '_blank', 'location=yes');
    ref.close();

    InAppBrowser.show:
    It will display InAppBrowser window, if it is hidden.

    InAppBrowser.executeScript:
    It can be used to inject javascript code into the window of inappbrowser.
    Example:
     

    var ref = cordova.InAppBrowser.open('http://google.com', '_blank', 'location=yes');
    ref.addEventListener('loadstop', function() {
        ref.executeScript({file: "script.js"});
    });

    InAppBrowser.insertCSS:
    It can be used to inject css file into InAppBrowser window.

    ref.insertCSS(details, callback);


    Example:
     

    var ref = cordova.InAppBrowser.open('http://google.com', '_blank', 'location=yes');
    ref.addEventListener('loadstop', function() {
        ref.insertCSS({file: "style.css"});
    });

    Hope this will help you to use InAppBrowser events. :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: