
- Ionic 基礎教程
- Ionic - 首頁
- Ionic - 概述
- Ionic - 環境搭建
- Ionic CSS 元件
- Ionic - 顏色
- Ionic - 內容
- Ionic - 頭部
- Ionic - 底部
- Ionic - 按鈕
- Ionic - 列表
- Ionic - 卡片
- Ionic - 表單
- Ionic - 開關
- Ionic - 複選框
- Ionic - 單選按鈕
- Ionic - 範圍選擇器
- Ionic - 選擇器
- Ionic - 標籤頁
- Ionic - 網格
- Ionic - 圖示
- Ionic - 內邊距
- Ionic Javascript 元件
- Ionic - JS 動作面板
- Ionic - JS 背景
- Ionic - JS 內容
- Ionic - JS 表單
- Ionic - JS 事件
- Ionic - JS 頭部
- Ionic - JS 底部
- Ionic - JS 鍵盤
- Ionic - JS 列表
- Ionic - JS 載入
- Ionic - JS 模態框
- Ionic - JS 導航
- Ionic - JS 彈出框
- Ionic - JS 彈窗
- Ionic - JS 滾動
- Ionic - JS 側邊選單
- Ionic - JS 滑動盒子
- Ionic - JS 標籤頁
- Ionic 高階概念
- Ionic - Cordova 整合
- Ionic - AdMob
- Ionic - 相機
- Ionic - Facebook
- Ionic - 應用內瀏覽器
- Ionic - 原生音訊
- Ionic - 定位
- Ionic - 媒體
- Ionic - 啟動畫面
- Ionic 有用資源
- Ionic - 快速指南
- Ionic - 有用資源
- Ionic - 討論
Ionic - Cordova InAppBrowser (Ionic 內嵌瀏覽器)
Cordova InAppBrowser 外掛用於在應用內網頁瀏覽器檢視中開啟外部連結。
使用瀏覽器
使用此外掛非常簡單。您只需開啟命令提示符視窗並安裝 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 方法
方法 | 引數 | 型別 | 詳情 |
---|---|---|---|
setDefaultOptions(parameter1) | options | 物件 | 用於為所有 InAppBrowser 設定全域性選項。 |
open(parameter1, parameter2, parameter3) | URL, target, options | 字串, 字串, 物件 | 有三個目標可用。**_blank** 將開啟新的 InAppBrowser 例項。**_system** 將開啟系統瀏覽器,**_self** 將使用當前瀏覽器例項。 |
close | / | / | 用於關閉 InAppBrowser。 |
Cordova InAppBrowser 事件
此外掛還提供可以與 **$rootScope** 組合的事件。
示例 | 詳情 |
---|---|
$rootScope.$on('$cordovaInAppBrowser:loadstart', function(e, event)); | 當 inAppBrowser 開始載入頁面時呼叫。 |
$rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event)); | 當 inAppBrowser 完成頁面載入時呼叫。 |
$rootScope.$on('$cordovaInAppBrowser:loaderror', function(e, event)); | 當 inAppBrowser 遇到錯誤時呼叫。 |
$rootScope.$on('$cordovaInAppBrowser:exit', function(e, event)); | 當 inAppBrowser 視窗關閉時呼叫。 |
廣告