Ionic-in-app-browser
提供:Dev Guides
イオン-Cordova InAppBrowser
Cordova InAppBrowserプラグインは、Webブラウザービュー内でアプリから外部リンクを開くために使用されます。
ブラウザを使用する
このプラグインを使い始めるのはとても簡単です。 必要なことは、コマンドプロンプトウィンドウを開いてCordovaプラグインをインストールすることだけです。
C:\Users\Username\Desktop\MyApp>cordova plugin add org.apache.cordova.inappbrowser
この手順により、 inAppBrowser の使用を開始できます。 これで、外部リンクにつながるボタンを作成し、プラグインをトリガーするための簡単な関数を追加できます。
HTMLコード
<button class = "button" ng-click = "openBrowser()">OPEN BROWSER</button>
コントローラコード
.controller('MyCtrl', function($scope, $cordovaInAppBrowser) {
var options = {
location: 'yes',
clearcache: 'yes',
toolbar: 'no'
};
$scope.openBrowser = function() {
$cordovaInAppBrowser.open('http://ngcordova.com', '_blank', options)
.then(function(event) {
//success
})
.catch(function(event) {
//error
});
}
})
ユーザーがボタンをタップすると、InAppBrowserは提供されたURLを開きます。
このプラグインでは、他のいくつかの方法を使用できます。そのうちのいくつかを次の表に示します。
Cordova $ inAppBrowserメソッド
Method | Parameters | Type | Details |
---|---|---|---|
setDefaultOptions(parameter1) | options | object | Used to set global options for all InAppBrowsers. |
open(parameter1, parameter2, parameter3) | URL, target, options | string, string, object | There are three targets available. _blank *will open new inAppBrowser instance. _system will open system browser and _self* will use current browser instance. |
close | / | / | Used to close InAppBrowser. |
Cordova InAppBrowserイベント
このプラグインは、 $ rootScope と組み合わせることができるイベントも提供します。
Example | Details |
---|---|
$rootScope.$on('$cordovaInAppBrowser:loadstart', function(e, event)); | Called when inAppBrowser start loading the page. |
$rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event)); | Called when inAppBrowser has finished loading the page. |
$rootScope.$on('$cordovaInAppBrowser:loaderror', function(e, event)); | Called when inAppBrowser has encountered error. |
$rootScope.$on('$cordovaInAppBrowser:exit', function(e, event)); | Called when inAppBrowser window is closed. |