UNPKG

28.1 kBMarkdownView Raw
1---
2title: Inappbrowser
3description: Open an in-app browser window.
4---
5<!--
6# license: Licensed to the Apache Software Foundation (ASF) under one
7# or more contributor license agreements. See the NOTICE file
8# distributed with this work for additional information
9# regarding copyright ownership. The ASF licenses this file
10# to you under the Apache License, Version 2.0 (the
11# "License"); you may not use this file except in compliance
12# with the License. You may obtain a copy of the License at
13#
14# http://www.apache.org/licenses/LICENSE-2.0
15#
16# Unless required by applicable law or agreed to in writing,
17# software distributed under the License is distributed on an
18# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19# KIND, either express or implied. See the License for the
20# specific language governing permissions and limitations
21# under the License.
22-->
23
24|Android 4.4|Android 5.1|Android 6.0|iOS 9.3|iOS 10.0|Windows 10 Store|Travis CI|
25|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
26|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-6.0,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-6.0,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios-9.3,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-9.3,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios-10.0,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-10.0,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-inappbrowser.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-inappbrowser)|
27
28# cordova-plugin-inappbrowser
29
30You can show helpful articles, videos, and web resources inside of your app. Users can view web pages without leaving your app.
31
32> To get a few ideas, check out the [sample](#sample) at the bottom of this page or go straight to the [reference](#reference) content.
33
34This plugin provides a web browser view that displays when calling `cordova.InAppBrowser.open()`.
35
36 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
37
38The `cordova.InAppBrowser.open()` function is defined to be a drop-in replacement
39for the `window.open()` function. Existing `window.open()` calls can use the
40InAppBrowser window, by replacing window.open:
41
42 window.open = cordova.InAppBrowser.open;
43
44The InAppBrowser window behaves like a standard web browser,
45and can't access Cordova APIs. For this reason, the InAppBrowser is recommended
46if you need to load third-party (untrusted) content, instead of loading that
47into the main Cordova webview. The InAppBrowser is not subject to the
48whitelist, nor is opening links in the system browser.
49
50The InAppBrowser provides by default its own GUI controls for the user (back,
51forward, done).
52
53For backwards compatibility, this plugin also hooks `window.open`.
54However, the plugin-installed hook of `window.open` can have unintended side
55effects (especially if this plugin is included only as a dependency of another
56plugin). The hook of `window.open` will be removed in a future major release.
57Until the hook is removed from the plugin, apps can manually restore the default
58behaviour:
59
60 delete window.open // Reverts the call back to it's prototype's default
61
62Although `window.open` is in the global scope, InAppBrowser is not available until after the `deviceready` event.
63
64 document.addEventListener("deviceready", onDeviceReady, false);
65 function onDeviceReady() {
66 console.log("window.open works well");
67 }
68
69Report 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)
70
71
72## <a id="reference">Reference</a>
73## Installation
74
75 cordova plugin add cordova-plugin-inappbrowser
76
77If you want all page loads in your app to go through the InAppBrowser, you can
78simply hook `window.open` during initialization. For example:
79
80 document.addEventListener("deviceready", onDeviceReady, false);
81 function onDeviceReady() {
82 window.open = cordova.InAppBrowser.open;
83 }
84
85## cordova.InAppBrowser.open
86
87Opens a URL in a new `InAppBrowser` instance, the current browser
88instance, or the system browser.
89
90 var ref = cordova.InAppBrowser.open(url, target, options);
91
92- __ref__: Reference to the `InAppBrowser` window when the target is set to `'_blank'`. _(InAppBrowser)_
93
94- __url__: The URL to load _(String)_. Call `encodeURI()` on this if the URL contains Unicode characters.
95
96- __target__: The target in which to load the URL, an optional parameter that defaults to `_self`. _(String)_
97
98 - `_self`: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the `InAppBrowser`.
99 - `_blank`: Opens in the `InAppBrowser`.
100 - `_system`: Opens in the system's web browser.
101
102- __options__: Options for the `InAppBrowser`. Optional, defaulting to: `location=yes`. _(String)_
103
104 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:
105
106 - __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off.
107
108 Android only:
109
110 - __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.
111 - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
112 - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
113 - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
114 - __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.
115 - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
116 - __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)).
117 - __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`).
118
119 iOS only:
120
121 - __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself.
122 - __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the UIWebViewBounce property.
123 - __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.
124 - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
125 - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
126 - __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
127 - __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
128 - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
129 - __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`)
130 - __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`).
131 - __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`).
132 - __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`).
133 - __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`).
134 - __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar to be at the top or bottom of the window.
135
136 Windows only:
137
138 - __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.
139 - __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.
140 - __hardwareback__: works the same way as on Android platform.
141
142### Supported Platforms
143
144- Amazon Fire OS
145- Android
146- BlackBerry 10
147- Firefox OS
148- iOS
149- OSX
150- Windows 8 and 8.1
151- Windows Phone 7 and 8
152- Browser
153
154### Example
155
156 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
157 var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ハングル'), '_blank', 'location=yes');
158
159### Firefox OS Quirks
160
161As plugin doesn't enforce any design there is a need to add some CSS rules if
162opened with `target='_blank'`. The rules might look like these
163
164``` css
165.inAppBrowserWrap {
166 background-color: rgba(0,0,0,0.75);
167 color: rgba(235,235,235,1.0);
168}
169.inAppBrowserWrap menu {
170 overflow: auto;
171 list-style-type: none;
172 padding-left: 0;
173}
174.inAppBrowserWrap menu li {
175 font-size: 25px;
176 height: 25px;
177 float: left;
178 margin: 0 10px;
179 padding: 3px 10px;
180 text-decoration: none;
181 color: #ccc;
182 display: block;
183 background: rgba(30,30,30,0.50);
184}
185.inAppBrowserWrap menu li.disabled {
186 color: #777;
187}
188```
189
190### OSX Quirks
191
192At the moment the only supported target in OSX is `_system`.
193
194`_blank` and `_self` targets are not yet implemented and are ignored silently. Pull requests and patches to get these to work are greatly appreciated.
195
196### Windows Quirks
197
198Windows 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'`.
199
200On 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.
201
202Similar to Firefox OS IAB window visual behaviour can be overridden via `inAppBrowserWrap`/`inAppBrowserWrapFullscreen` CSS classes
203
204### Browser Quirks
205
206- Plugin is implemented via iframe,
207
208- Navigation history (`back` and `forward` buttons in LocationBar) is not implemented.
209
210## InAppBrowser
211
212The object returned from a call to `cordova.InAppBrowser.open` when the target is set to `'_blank'`.
213
214### Methods
215
216- addEventListener
217- removeEventListener
218- close
219- show
220- hide
221- executeScript
222- insertCSS
223
224## InAppBrowser.addEventListener
225
226> Adds a listener for an event from the `InAppBrowser`. (Only available when the target is set to `'_blank'`)
227
228 ref.addEventListener(eventname, callback);
229
230- __ref__: reference to the `InAppBrowser` window _(InAppBrowser)_
231
232- __eventname__: the event to listen for _(String)_
233
234 - __loadstart__: event fires when the `InAppBrowser` starts to load a URL.
235 - __loadstop__: event fires when the `InAppBrowser` finishes loading a URL.
236 - __loaderror__: event fires when the `InAppBrowser` encounters an error when loading a URL.
237 - __exit__: event fires when the `InAppBrowser` window is closed.
238
239- __callback__: the function that executes when the event fires. The function is passed an `InAppBrowserEvent` object as a parameter.
240
241## Example
242
243```javascript
244
245var inAppBrowserRef;
246
247function showHelp(url) {
248
249 var target = "_blank";
250
251 var options = "location=yes,hidden=yes";
252
253 inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);
254
255 inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
256
257 inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);
258
259 inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);
260
261}
262
263function loadStartCallBack() {
264
265 $('#status-message').text("loading please wait ...");
266
267}
268
269function loadStopCallBack() {
270
271 if (inAppBrowserRef != undefined) {
272
273 inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" });
274
275 $('#status-message').text("");
276
277 inAppBrowserRef.show();
278 }
279
280}
281
282function loadErrorCallBack(params) {
283
284 $('#status-message').text("");
285
286 var scriptErrorMesssage =
287 "alert('Sorry we cannot open that page. Message from the server is : "
288 + params.message + "');"
289
290 inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
291
292 inAppBrowserRef.close();
293
294 inAppBrowserRef = undefined;
295
296}
297
298function executeScriptCallBack(params) {
299
300 if (params[0] == null) {
301
302 $('#status-message').text(
303 "Sorry we couldn't open that page. Message from the server is : '"
304 + params.message + "'");
305 }
306
307}
308
309```
310
311### InAppBrowserEvent Properties
312
313- __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, or `exit`. _(String)_
314
315- __url__: the URL that was loaded. _(String)_
316
317- __code__: the error code, only in the case of `loaderror`. _(Number)_
318
319- __message__: the error message, only in the case of `loaderror`. _(String)_
320
321
322### Supported Platforms
323
324- Amazon Fire OS
325- Android
326- iOS
327- Windows 8 and 8.1
328- Windows Phone 7 and 8
329- Browser
330
331### Browser Quirks
332
333`loadstart` and `loaderror` events are not being fired.
334
335### Quick Example
336
337 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
338 ref.addEventListener('loadstart', function(event) { alert(event.url); });
339
340## InAppBrowser.removeEventListener
341
342> Removes a listener for an event from the `InAppBrowser`. (Only available when the target is set to `'_blank'`)
343
344 ref.removeEventListener(eventname, callback);
345
346- __ref__: reference to the `InAppBrowser` window. _(InAppBrowser)_
347
348- __eventname__: the event to stop listening for. _(String)_
349
350 - __loadstart__: event fires when the `InAppBrowser` starts to load a URL.
351 - __loadstop__: event fires when the `InAppBrowser` finishes loading a URL.
352 - __loaderror__: event fires when the `InAppBrowser` encounters an error loading a URL.
353 - __exit__: event fires when the `InAppBrowser` window is closed.
354
355- __callback__: the function to execute when the event fires.
356The function is passed an `InAppBrowserEvent` object.
357
358### Supported Platforms
359
360- Amazon Fire OS
361- Android
362- iOS
363- Windows 8 and 8.1
364- Windows Phone 7 and 8
365- Browser
366
367### Quick Example
368
369 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
370 var myCallback = function(event) { alert(event.url); }
371 ref.addEventListener('loadstart', myCallback);
372 ref.removeEventListener('loadstart', myCallback);
373
374## InAppBrowser.close
375
376> Closes the `InAppBrowser` window.
377
378 ref.close();
379
380- __ref__: reference to the `InAppBrowser` window _(InAppBrowser)_
381
382### Supported Platforms
383
384- Amazon Fire OS
385- Android
386- Firefox OS
387- iOS
388- Windows 8 and 8.1
389- Windows Phone 7 and 8
390- Browser
391
392### Quick Example
393
394 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
395 ref.close();
396
397## InAppBrowser.show
398
399> Displays an InAppBrowser window that was opened hidden. Calling this has no effect if the InAppBrowser was already visible.
400
401 ref.show();
402
403- __ref__: reference to the InAppBrowser window (`InAppBrowser`)
404
405### Supported Platforms
406
407- Amazon Fire OS
408- Android
409- iOS
410- Windows 8 and 8.1
411- Browser
412
413### Quick Example
414
415 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes');
416 // some time later...
417 ref.show();
418
419## InAppBrowser.hide
420
421> Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden.
422
423 ref.hide();
424
425- __ref__: reference to the InAppBrowser window (`InAppBrowser`)
426
427### Supported Platforms
428
429- Amazon Fire OS
430- Android
431- iOS
432- Windows 8 and 8.1
433
434### Quick Example
435
436 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank');
437 // some time later...
438 ref.hide();
439
440## InAppBrowser.executeScript
441
442> Injects JavaScript code into the `InAppBrowser` window. (Only available when the target is set to `'_blank'`)
443
444 ref.executeScript(details, callback);
445
446- __ref__: reference to the `InAppBrowser` window. _(InAppBrowser)_
447
448- __injectDetails__: details of the script to run, specifying either a `file` or `code` key. _(Object)_
449 - __file__: URL of the script to inject.
450 - __code__: Text of the script to inject.
451
452- __callback__: the function that executes after the JavaScript code is injected.
453 - If the injected script is of type `code`, the callback executes
454 with a single parameter, which is the return value of the
455 script, wrapped in an `Array`. For multi-line scripts, this is
456 the return value of the last statement, or the last expression
457 evaluated.
458
459### Supported Platforms
460
461- Amazon Fire OS
462- Android
463- iOS
464- Windows 8 and 8.1
465- Browser
466
467### Quick Example
468
469 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
470 ref.addEventListener('loadstop', function() {
471 ref.executeScript({file: "myscript.js"});
472 });
473
474### Browser Quirks
475
476- only __code__ key is supported.
477
478### Windows Quirks
479
480Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.webview.invokescriptasync.aspx) the invoked script can return only string values, otherwise the parameter, passed to __callback__ will be `[null]`.
481
482## InAppBrowser.insertCSS
483
484> Injects CSS into the `InAppBrowser` window. (Only available when the target is set to `'_blank'`)
485
486 ref.insertCSS(details, callback);
487
488- __ref__: reference to the `InAppBrowser` window _(InAppBrowser)_
489
490- __injectDetails__: details of the script to run, specifying either a `file` or `code` key. _(Object)_
491 - __file__: URL of the stylesheet to inject.
492 - __code__: Text of the stylesheet to inject.
493
494- __callback__: the function that executes after the CSS is injected.
495
496### Supported Platforms
497
498- Amazon Fire OS
499- Android
500- iOS
501- Windows
502
503### Quick Example
504
505 var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
506 ref.addEventListener('loadstop', function() {
507 ref.insertCSS({file: "mystyles.css"});
508 });
509__
510
511## <a id="sample"></a>Sample: Show help pages with an InAppBrowser
512
513You can use this plugin to show helpful documentation pages within your app. Users can view online help documents and then close them without leaving the app.
514
515Here's a few snippets that show how you do this.
516
517* [Give users a way to ask for help](#give).
518* [Load a help page](#load).
519* [Let users know that you're getting their page ready](#let).
520* [Show the help page](#show).
521* [Handle page errors](#handle).
522
523### <a id="give"></a>Give users a way to ask for help
524
525There's lots of ways to do this in your app. A drop down list is a simple way to do that.
526
527```html
528
529<select id="help-select">
530 <option value="default">Need help?</option>
531 <option value="article">Show me a helpful article</option>
532 <option value="video">Show me a helpful video</option>
533 <option value="search">Search for other topics</option>
534</select>
535
536```
537
538Gather the users choice in the ``onDeviceReady`` function of the page and then send an appropriate URL to a helper function in some shared library file. Our helper function is named ``showHelp()`` and we'll write that function next.
539
540```javascript
541
542$('#help-select').on('change', function (e) {
543
544 var url;
545
546 switch (this.value) {
547
548 case "article":
549 url = "https://cordova.apache.org/docs/en/latest/"
550 + "reference/cordova-plugin-inappbrowser/index.html";
551 break;
552
553 case "video":
554 url = "https://youtu.be/F-GlVrTaeH0";
555 break;
556
557 case "search":
558 url = "https://www.google.com/#q=inAppBrowser+plugin";
559 break;
560 }
561
562 showHelp(url);
563
564});
565
566```
567
568### <a id="load"></a>Load a help page
569
570We'll use the ``open`` function to load the help page. We're setting the ``hidden`` property to ``yes`` so that we can show the browser only after the page content has loaded. That way, users don't see a blank browser while they wait for content to appear. When the ``loadstop`` event is raised, we'll know when the content has loaded. We'll handle that event shortly.
571
572```javascript
573
574function showHelp(url) {
575
576 var target = "_blank";
577
578 var options = "location=yes,hidden=yes";
579
580 inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);
581
582 inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
583
584 inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);
585
586 inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);
587
588}
589
590```
591
592### <a id="let"></a>Let users know that you're getting their page ready
593
594Because the browser doesn't immediately appear, we can use the ``loadstart`` event to show a status message, progress bar, or other indicator. This assures users that content is on the way.
595
596```javascript
597
598function loadStartCallBack() {
599
600 $('#status-message').text("loading please wait ...");
601
602}
603
604```
605
606### <a id="show"></a>Show the help page
607
608When the ``loadstopcallback`` event is raised, we know that the content has loaded and we can make the browser visible. This sort of trick can create the impression of better performance. The truth is that whether you show the browser before content loads or not, the load times are exactly the same.
609
610```javascript
611
612function loadStopCallBack() {
613
614 if (inAppBrowserRef != undefined) {
615
616 inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" });
617
618 $('#status-message').text("");
619
620 inAppBrowserRef.show();
621 }
622
623}
624
625```
626You might have noticed the call to the ``insertCSS`` function. This serves no particular purpose in our scenario. But it gives you an idea of why you might use it. In this case, we're just making sure that the font size of your pages have a certain size. You can use this function to insert any CSS style elements. You can even point to a CSS file in your project.
627
628### <a id="handle"></a>Handle page errors
629
630Sometimes a page no longer exists, a script error occurs, or a user lacks permission to view the resource. How or if you handle that situation is completely up to you and your design. You can let the browser show that message or you can present it in another way.
631
632We'll try to show that error in a message box. We can do that by injecting a script that calls the ``alert`` function. That said, this won't work in browsers on Windows devices so we'll have to look at the parameter of the ``executeScript`` callback function to see if our attempt worked. If it didn't work out for us, we'll just show the error message in a ``<div>`` on the page.
633
634```javascript
635
636function loadErrorCallBack(params) {
637
638 $('#status-message').text("");
639
640 var scriptErrorMesssage =
641 "alert('Sorry we cannot open that page. Message from the server is : "
642 + params.message + "');"
643
644 inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
645
646 inAppBrowserRef.close();
647
648 inAppBrowserRef = undefined;
649
650}
651
652function executeScriptCallBack(params) {
653
654 if (params[0] == null) {
655
656 $('#status-message').text(
657 "Sorry we couldn't open that page. Message from the server is : '"
658 + params.message + "'");
659 }
660
661}
662
663```
664
665## More Usage Info
666
667### Local Urls ( source is in the app package )
668```
669var iab = cordova.InAppBrowser;
670
671iab.open('local-url.html'); // loads in the Cordova WebView
672iab.open('local-url.html', '_self'); // loads in the Cordova WebView
673iab.open('local-url.html', '_system'); // Security error: system browser, but url will not load (iOS)
674iab.open('local-url.html', '_blank'); // loads in the InAppBrowser
675iab.open('local-url.html', 'random_string'); // loads in the InAppBrowser
676iab.open('local-url.html', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
677
678```
679
680
681
682### Whitelisted Content
683
684```
685var iab = cordova.InAppBrowser;
686
687iab.open('http://whitelisted-url.com'); // loads in the Cordova WebView
688iab.open('http://whitelisted-url.com', '_self'); // loads in the Cordova WebView
689iab.open('http://whitelisted-url.com', '_system'); // loads in the system browser
690iab.open('http://whitelisted-url.com', '_blank'); // loads in the InAppBrowser
691iab.open('http://whitelisted-url.com', 'random_string'); // loads in the InAppBrowser
692
693iab.open('http://whitelisted-url.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
694
695```
696
697### Urls that are not white-listed
698
699```
700var iab = cordova.InAppBrowser;
701
702iab.open('http://url-that-fails-whitelist.com'); // loads in the InAppBrowser
703iab.open('http://url-that-fails-whitelist.com', '_self'); // loads in the InAppBrowser
704iab.open('http://url-that-fails-whitelist.com', '_system'); // loads in the system browser
705iab.open('http://url-that-fails-whitelist.com', '_blank'); // loads in the InAppBrowser
706iab.open('http://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser
707iab.open('http://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
708
709```