2013-08-07 48 views
1

我一直在尋找方法來打開一個html本地級別,本地我的意思是說html是在phonegap的應用程序的www文件夾中,inappbrowser用InAppbrowser打開本地HTML

var about = window.open("About.html", "_blank", "location=yes"); 

這是代碼,我打算做這行了,但顯然是不行的,如果有人可以幫助我,我將非常感激。

回答

-1

你寫的代碼是正確的。它正在inappbrowser中打開頁面。

現在的事情是你必須確保你在設備準備好之後調用它。

另外檢查你使用的是2.x版本的cordova框架。如果您在使用inappbrowser時遇到問題,請提供更多信息。

var app = { 
    // Application Constructor 
    initialize: function() { 
     this.bindEvents(); 
    }, 
    // Bind Event Listeners 
    // 
    // Bind any events that are required on startup. Common events are: 
    // 'load', 'deviceready', 'offline', and 'online'. 
    bindEvents: function() { 
      document.addEventListener('deviceready', this.onDeviceReady, false); 
    }, 
    // deviceready Event Handler 
    // 
    // The scope of 'this' is the event. In order to call the 'receivedEvent' 
    // function, we must explicity call 'app.receivedEvent(...);' 
    onDeviceReady: function() { 
     app.receivedEvent('deviceready'); 
    }, 
    // Update DOM on a Received Event 
    receivedEvent: function(id) { 
     var about = window.open("about.html", "_blank", "location=yes"); 
     console.log('Received Event: ' + id); 
    } 
}; 
0

您是否使用Phonegap 3.0.0?我認爲這是這個Phonegap版本的一個錯誤。

我一直用這個作爲一種解決辦法(打開一個inappbrowser實例):

// Image zoom 
$('#container').on('tap', '#content.cmscontent img', function() { 
    var browser = window.open((navigator.userAgent.indexOf('Android') != -1 ? 'file:///android_asset/www/' : '') + encodeURI($(this).attr('src')), '_blank', 'location=no,toolbar=yes,enableViewportScale=yes,transitionstyle=crossdissolve'); 
}); 

見我加(navigator.userAgent.indexOf('Android') != -1 ? 'file:///android_asset/www/' : '')作爲URL前的前綴。現在,它會檢測您的應用程序在Android上,並在其前面添加本地網址。

+0

感謝您的文章,但目前我正在開發項目爲ios平臺很可能該項目也將開發爲Android –

0

謝謝您的回答,並實現它的工作顯然的問題是,有被清洗的項目,爲此不加www的about.html

但現在我有一個問題,我將已經看到假裝展示了一個關於應用程序的信息,爲此顯示了ios版本和設備名稱。爲此,我使用對象名稱和版本設備的屬性。出於某種原因,我不知道但索引文件中沒有該屬性,因此我決定將這些屬性傳遞給html url,例如:

var about = window.open("About.html?"+device.name+"&"+device.version, "_blank", "location=yes"); 

和about.html處理這些變量有:

var cadGET = location.search.substr(1,location.search.length); 

但不顯示的HTML inappbrowser和地址欄只顯示加載...

知道,如果inappbrowser支持通過URL參數?