diff --git a/README.md b/README.md index 5bf8c4d..4c16946 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,33 @@ Cordova_in_app_browser.ai_clear_cache true] in (* Opens in the Cordova WebView if the URL is in the white list *) i#open_ "https://ocaml.org" (Cordova_in_app_browser.target_self) opt ``` + +The function "open_t" is hte same as "open" but it return a "typed" +result: an object of type "inAppBrowser" that can be used later. An +"inAppBrowser" object is te only way to to call the function +"addEventListener" and "close" of this ibrary for example + +```OCaml +let popup = + Cordova_in_app_browser.open_t + ~url:"https://www.google.com" ~tgt:Blank + ~option:"location=yes" +in +Cordova_in_app_browser.addEventListener popup ~eventname:"loadstop" +~f:(fun evt -> + ignore (print_endline "Hello World"); + Cordova_in_app_browser.close popup) +``` + +You can access the 5 properties of the argument of an added +"EventListener" with this functions: + °Cordova_in_app_browser.type: either "loadstart", + "loadstop", "loaderror", "message", or "exit" + °Cordova_in_app_browser.url: not available for every + event type (not for "exit"). + °Cordova_in_app_browser.code: only available for event + with an error code. + °Cordova_in_app_browser.message: only available for + "loaderror" event type + °Cordova_in_app_browser.data: onlys available for + "message event type diff --git a/src/cordova_in_app_browser.mli b/src/cordova_in_app_browser.mli index ab5f703..33cf761 100644 --- a/src/cordova_in_app_browser.mli +++ b/src/cordova_in_app_browser.mli @@ -235,16 +235,31 @@ type inAppBrowser val open_t : url:string -> tgt:target -> option:string -> inAppBrowser [@@js.global "cordova.InAppBrowser.open"] +type inAppBrowserEvent + val addEventListener : inAppBrowser -> (*Where to add the listener*) eventname:string -> (*The event name*) - f:(Ojs.t -> unit) -> + f:(inAppBrowserEvent -> unit) -> (*The call_back*) unit [@@js.call] +(*Getting access to the "InAppBrowserEvent" properties*) + +val type_ : inAppBrowserEvent -> string [@@js.get "type"] + +val url : inAppBrowserEvent -> string [@@js.get "url"] + +val code : inAppBrowserEvent -> int [@@js.get "code"] + +val message : inAppBrowserEvent -> string [@@js.get "message"] + +val data : inAppBrowserEvent -> string [@@js.get "data"] + +(*Indicate to close an open InAppBrowser object*) val close : inAppBrowser -> unit [@@js.call] (*That function indicate if the plugin "cordova-InAppBrowser" is currently available*)