diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-09-21 18:43:03 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-09-21 18:43:03 +0200 |
| commit | 7f6c5134780ad3cedc718772b40578f0170f200e (patch) | |
| tree | 15a120d91855ae66f42111e05f696e5600a9b832 /StoneIsland/plugins/cordova-plugin-inappbrowser/README.md | |
| parent | 853bd5fa85812316a72b2f5ce755dc0facb91932 (diff) | |
cordova-plugin-inappbrowser welcome to the family!!
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-inappbrowser/README.md')
| -rw-r--r-- | StoneIsland/plugins/cordova-plugin-inappbrowser/README.md | 242 |
1 files changed, 133 insertions, 109 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-inappbrowser/README.md b/StoneIsland/plugins/cordova-plugin-inappbrowser/README.md index e7e96972..4df96070 100644 --- a/StoneIsland/plugins/cordova-plugin-inappbrowser/README.md +++ b/StoneIsland/plugins/cordova-plugin-inappbrowser/README.md @@ -21,9 +21,9 @@ description: Open an in-app browser window. # under the License. --> -|Android|iOS| Windows 8.1 Store | Windows 8.1 Phone | Windows 10 Store | Travis CI | -|:-:|:-:|:-:|:-:|:-:|:-:| -|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser/)|[](https://travis-ci.org/apache/cordova-plugin-inappbrowser)| +|AppVeyor|Travis CI| +|:-:|:-:| +|[](https://ci.appveyor.com/project/ApacheSoftwareFoundation/cordova-plugin-inappbrowser)|[](https://travis-ci.org/apache/cordova-plugin-inappbrowser)| # cordova-plugin-inappbrowser @@ -35,12 +35,18 @@ This plugin provides a web browser view that displays when calling `cordova.InAp var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); +### `window.open` + The `cordova.InAppBrowser.open()` function is defined to be a drop-in replacement for the `window.open()` function. Existing `window.open()` calls can use the InAppBrowser window, by replacing window.open: window.open = cordova.InAppBrowser.open; +If you change the browsers `window.open` function this way, it can have unintended side +effects (especially if this plugin is included only as a dependency of another +plugin). + The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs. For this reason, the InAppBrowser is recommended if you need to load third-party (untrusted) content, instead of loading that @@ -50,26 +56,6 @@ whitelist, nor is opening links in the system browser. The InAppBrowser provides by default its own GUI controls for the user (back, forward, done). -For backwards compatibility, this plugin also hooks `window.open`. -However, the plugin-installed hook of `window.open` can have unintended side -effects (especially if this plugin is included only as a dependency of another -plugin). The hook of `window.open` will be removed in a future major release. -Until the hook is removed from the plugin, apps can manually restore the default -behaviour: - - delete window.open // Reverts the call back to it's prototype's default - -Although `window.open` is in the global scope, InAppBrowser is not available until after the `deviceready` event. - - document.addEventListener("deviceready", onDeviceReady, false); - function onDeviceReady() { - console.log("window.open works well"); - } - -Report issues with this plugin on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20InAppBrowser%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC) - - -## <a id="reference">Reference ## Installation cordova plugin add cordova-plugin-inappbrowser @@ -101,97 +87,86 @@ instance, or the system browser. - __options__: Options for the `InAppBrowser`. Optional, defaulting to: `location=yes`. _(String)_ - The `options` string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive. All platforms support the value below: + The `options` string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive. + + All platforms support: - __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off. - Android only: + Android supports these additional options: - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally. + - __beforeload__: set to enable the `beforeload` event to modify which pages are actually loaded in the browser. Accepted values are `get` to intercept only GET requests, `post` to intercept on POST requests or `yes` to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set `beforeload=post` it will raise an error). - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened - - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. + - __closebuttoncaption__: set to a string to use as the close button's caption instead of a X. Note that you need to localize this value yourself. + - __closebuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the + close button color from default, regardless of being a text or default X. Only has effect if user has location set to `yes`. + - __footer__: set to `yes` to show a close button in the footer similar to the iOS __Done__ button. + The close button will appear the same as for the header hence use __closebuttoncaption__ and __closebuttoncolor__ to set its properties. + - __footercolor__: set to a valid hex color string, for example `#00ff00` or `#CC00ff00` (`#aarrggbb`) , and it will change the footer color from default. + Only has effect if user has __footer__ set to `yes`. - __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser. + - __hidenavigationbuttons__: set to `yes` to hide the navigation buttons on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`. + - __hideurlbar__: set to `yes` to hide the url bar on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`. + - __navigationbuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of both navigation buttons from default. Only has effect if user has location set to `yes` and not hidenavigationbuttons set to `yes`. + - __toolbarcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color the toolbar from default. Only has effect if user has location set to `yes`. + - __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the right and close button to the left. Default value is `no`. + - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). - __shouldPauseOnSuspend__: Set to `yes` to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues like described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)). + - __useWideViewPort__: Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is `no`, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is `yes` and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. (defaults to `yes`). + - __fullscreen__: Sets whether the InappBrowser WebView is displayed fullscreen or not. In fullscreen mode, the status bar is hidden. Default value is `yes`. - iOS only: + iOS supports these additional options: - - __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself. - - __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the UIWebViewBounce property. - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally. + - __beforeload__: set to enable the `beforeload` event to modify which pages are actually loaded in the browser. Accepted values are `get` to intercept only GET requests, `post` to intercept on POST requests or `yes` to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set `beforeload=post` it will raise an error). - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened - - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened + - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened. For WKWebView, requires iOS 11+ on target device. + - __cleardata__: set to `yes` to have the browser's entire local storage cleared (cookies, HTML5 local storage, IndexedDB, etc.) before the new window is opened + - __closebuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default __Done__ button's color. Only applicable if toolbar is not disabled. + - __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself. + - __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the the bounce of the WKWebView's UIScrollView. + - __hidenavigationbuttons__: set to `yes` or `no` to turn the toolbar navigation buttons on or off (defaults to `no`). Only applicable if toolbar is not disabled. + - __navigationbuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color. Only applicable if navigation buttons are visible. - __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`) + - __toolbarcolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color of the toolbar. Only applicable if toolbar is not disabled. + - __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled. + - __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left. - __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). - - __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`) - - __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). - - __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). - - __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle) (defaults to `fullscreen`). - - __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle) (defaults to `coververtical`). + - __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`). + - __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) (defaults to `fullscreen`). + - __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](https://developer.apple.com/documentation/uikit/uimodaltransitionstyle) (defaults to `coververtical`). - __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar to be at the top or bottom of the window. + - __hidespinner__: Set to `yes` or `no` to change the visibility of the loading indicator (defaults to `no`). - Windows only: + Windows supports these additional options: - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally. - - __fullscreen__: set to `yes` to create the browser control without a border around it. Please note that if __location=no__ is also specified, there will be no control presented to user to close IAB window. - __hardwareback__: works the same way as on Android platform. + - __fullscreen__: set to `yes` to create the browser control without a border around it. Please note that if __location=no__ is also specified, there will be no control presented to user to close IAB window. + ### Supported Platforms -- Amazon Fire OS - Android -- BlackBerry 10 -- Firefox OS -- iOS -- Windows 8 and 8.1 -- Windows Phone 7 and 8 - Browser +- iOS +- OSX +- Windows ### Example var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ハングル'), '_blank', 'location=yes'); -### Firefox OS Quirks - -As plugin doesn't enforce any design there is a need to add some CSS rules if -opened with `target='_blank'`. The rules might look like these - -``` css -.inAppBrowserWrap { - background-color: rgba(0,0,0,0.75); - color: rgba(235,235,235,1.0); -} -.inAppBrowserWrap menu { - overflow: auto; - list-style-type: none; - padding-left: 0; -} -.inAppBrowserWrap menu li { - font-size: 25px; - height: 25px; - float: left; - margin: 0 10px; - padding: 3px 10px; - text-decoration: none; - color: #ccc; - display: block; - background: rgba(30,30,30,0.50); -} -.inAppBrowserWrap menu li.disabled { - color: #777; -} -``` - -### Windows Quirks +### OSX Quirks -Windows 8.0, 8.1 and Windows Phone 8.1 don't support remote urls to be opened in the Cordova WebView so remote urls are always showed in the system's web browser if opened with `target='_self'`. +At the moment the only supported target in OSX is `_system`. -On Windows 10 if the URL is NOT in the white list and is opened with `target='_self'` it will be showed in the system's web browser instead of InAppBrowser popup. - -Similar to Firefox OS IAB window visual behaviour can be overridden via `inAppBrowserWrap`/`inAppBrowserWrapFullscreen` CSS classes +`_blank` and `_self` targets are not yet implemented and are ignored silently. Pull requests and patches to get these to work are greatly appreciated. ### Browser Quirks @@ -209,12 +184,13 @@ The object returned from a call to `cordova.InAppBrowser.open` when the target i - removeEventListener - close - show +- hide - executeScript - insertCSS ## InAppBrowser.addEventListener -> Adds a listener for an event from the `InAppBrowser`. +> Adds a listener for an event from the `InAppBrowser`. (Only available when the target is set to `'_blank'`) ref.addEventListener(eventname, callback); @@ -226,6 +202,8 @@ The object returned from a call to `cordova.InAppBrowser.open` when the target i - __loadstop__: event fires when the `InAppBrowser` finishes loading a URL. - __loaderror__: event fires when the `InAppBrowser` encounters an error when loading a URL. - __exit__: event fires when the `InAppBrowser` window is closed. + - __beforeload__: event fires when the `InAppBrowser` decides whether to load an URL or not (only with option `beforeload` set). + - __message__: event fires when the `InAppBrowser` receives a message posted from the page loaded inside the `InAppBrowser` Webview. - __callback__: the function that executes when the event fires. The function is passed an `InAppBrowserEvent` object as a parameter. @@ -239,7 +217,7 @@ function showHelp(url) { var target = "_blank"; - var options = "location=yes,hidden=yes"; + var options = "location=yes,hidden=yes,beforeload=yes"; inAppBrowserRef = cordova.InAppBrowser.open(url, target, options); @@ -249,6 +227,9 @@ function showHelp(url) { inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack); + inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack); + + inAppBrowserRef.addEventListener('message', messageCallBack); } function loadStartCallBack() { @@ -261,7 +242,14 @@ function loadStopCallBack() { if (inAppBrowserRef != undefined) { - inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" }); + 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(""); @@ -297,11 +285,29 @@ function executeScriptCallBack(params) { } +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); +} + ``` ### InAppBrowserEvent Properties -- __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, or `exit`. _(String)_ +- __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, `message` or `exit`. _(String)_ - __url__: the URL that was loaded. _(String)_ @@ -309,19 +315,24 @@ function executeScriptCallBack(params) { - __message__: the error message, only in the case of `loaderror`. _(String)_ +- __data__: the message contents , only in the case of `message`. A stringified JSON object. _(String)_ + ### Supported Platforms -- Amazon Fire OS - Android -- iOS -- Windows 8 and 8.1 -- Windows Phone 7 and 8 - Browser +- iOS +- Windows +- OSX ### Browser Quirks -`loadstart` and `loaderror` events are not being fired. +`loadstart`, `loaderror`, `message` events are not fired. + +### Windows Quirks + +`message` event is not fired. ### Quick Example @@ -330,7 +341,7 @@ function executeScriptCallBack(params) { ## InAppBrowser.removeEventListener -> Removes a listener for an event from the `InAppBrowser`. +> Removes a listener for an event from the `InAppBrowser`. (Only available when the target is set to `'_blank'`) ref.removeEventListener(eventname, callback); @@ -342,18 +353,17 @@ function executeScriptCallBack(params) { - __loadstop__: event fires when the `InAppBrowser` finishes loading a URL. - __loaderror__: event fires when the `InAppBrowser` encounters an error loading a URL. - __exit__: event fires when the `InAppBrowser` window is closed. + - __message__: event fires when the `InAppBrowser` receives a message posted from the page loaded inside the `InAppBrowser` Webview. - __callback__: the function to execute when the event fires. The function is passed an `InAppBrowserEvent` object. ### Supported Platforms -- Amazon Fire OS - Android -- iOS -- Windows 8 and 8.1 -- Windows Phone 7 and 8 - Browser +- iOS +- Windows ### Quick Example @@ -372,13 +382,10 @@ The function is passed an `InAppBrowserEvent` object. ### Supported Platforms -- Amazon Fire OS - Android -- Firefox OS -- iOS -- Windows 8 and 8.1 -- Windows Phone 7 and 8 - Browser +- iOS +- Windows ### Quick Example @@ -395,11 +402,10 @@ The function is passed an `InAppBrowserEvent` object. ### Supported Platforms -- Amazon Fire OS - Android -- iOS -- Windows 8 and 8.1 - Browser +- iOS +- Windows ### Quick Example @@ -407,9 +413,29 @@ The function is passed an `InAppBrowserEvent` object. // some time later... ref.show(); +## InAppBrowser.hide + +> Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden. + + ref.hide(); + +- __ref__: reference to the InAppBrowser window (`InAppBrowser`) + +### Supported Platforms + +- Android +- iOS +- Windows + +### Quick Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank'); + // some time later... + ref.hide(); + ## InAppBrowser.executeScript -> Injects JavaScript code into the `InAppBrowser` window +> Injects JavaScript code into the `InAppBrowser` window. (Only available when the target is set to `'_blank'`) ref.executeScript(details, callback); @@ -428,11 +454,10 @@ The function is passed an `InAppBrowserEvent` object. ### Supported Platforms -- Amazon Fire OS - Android -- iOS -- Windows 8 and 8.1 - Browser +- iOS +- Windows ### Quick Example @@ -451,7 +476,7 @@ Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.cont ## InAppBrowser.insertCSS -> Injects CSS into the `InAppBrowser` window. +> Injects CSS into the `InAppBrowser` window. (Only available when the target is set to `'_blank'`) ref.insertCSS(details, callback); @@ -465,7 +490,6 @@ Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.cont ### Supported Platforms -- Amazon Fire OS - Android - iOS - Windows @@ -583,7 +607,7 @@ function loadStopCallBack() { if (inAppBrowserRef != undefined) { - inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" }); + inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;}" }); $('#status-message').text(""); @@ -676,4 +700,4 @@ iab.open('http://url-that-fails-whitelist.com', '_blank'); // loads in th iab.open('http://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser iab.open('http://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar -```
\ No newline at end of file +``` |
