2012-03-20 82 views
3

在我的應用程序中搜索合適的方式打開瀏覽器後,我遇到了ChildBrowser,它看起來像提供了我之後的所有內容。下面幾個教程後,我似乎無法讓插件工作。我爲外部主機編輯了PhoneGap.plist文件,其值爲「*」,我在插件中添加了ChildBrowserCommand,但是當我運行應用程序時,沒有任何反應,當我單擊鏈接時。我在文檔的頭部有以下代碼;ChildBrowser Phonegap無法正常工作

<script type="text/javascript"> 
    var childBrowser; 

    function onBodyLoad() 
    { 
     document.addEventListener("deviceready", onDeviceReady, false); 
    } 

    //Phonegap ready to go 
    function onDeviceReady() 
    { 
     alert("PhoneGap is ready"); 
     childBrowser = ChildBrowser.install(); 
    } 

    function openChildBrowser(url) 
    { 
     try { 
      window.plugins.childBrowser.ShowWebPage(url); 
      //childBrowser.showWebPage(url); 
     } 
     cathc(err) 
     { 
      alert(err); 
     } 
    } 

</script> 

我有ChildBrowser包括直後,我的phoneGap.js文件,但似乎無法得到它的運行,我沒有得到任何記錄在控制檯的錯誤。有誰知道什麼是錯的,或者至少讓我指向正確的方向?

+0

我有一個使用FACEBOOK與childbrowser一個測試項目,您可以檢查它以供參考https://github.com/dhavaln/phonegap-facebook – dhaval 2012-03-20 13:39:41

+0

確保'<插件名稱=」 ChildBrowser「value =」com.phonegap.plugins.childBrowser.ChildBrowser「/>'在'/ res/xml/plugins.xml中定義' – dhaval 2012-03-20 13:40:53

+0

感謝評論@dhaval。我沒有一個plugins.xml文件,這導致我相信這可能是問題。但是,我沒有'/ res/xml ...'文件夾。當我創建文件時,是否將其放入我的www文件夾的根目錄中? – JPK 2012-03-20 17:04:05

回答

0

花了幾個小時/天在這個話題上追逐了許多令人困惑的頁面之後,我終於在blog page中找到了一套簡明的說明。請務必抓取最新的代碼,如github page所示。我成功地讓ChildBrowser插件與在OSX 10.7.3中運行的Xcode 4.3中的PhoneGap 1.5.0一起工作 - 並在iOS 4和5中進行了測試。我發現的限制是它只能在縱向模式下工作。我現在正在追求一個包含景觀模式的決議。

1

我的合作伙伴編寫了一個分步教程,用於將ChildBrowser插件添加到PhoneGap Android項目here

+0

感謝您的鏈接,但我試圖讓它在iphone/ipad上工作 – JPK 2012-03-21 12:51:54

+0

好的,我爲你的問題添加了一個ios標籤。祝你好運! – 2012-03-21 15:20:12

+0

感謝您的意見 – JPK 2012-03-21 15:31:10

3

下面的這段代碼適用於我。

<!DOCTYPE html> 
<html> 
<head> 
    <title>My External Page</title> 
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1.0"/> 
    <meta name="format-detection" content="telephone=no"/> 

    <!--iPhone on Safari Standalone mode--> 
    <meta name="apple-mobile-web-app-capable" content="yes" /> 

    <!--Hide iPhone on Safari Native Top Status Bar--> 
    <meta name="apple-mobile-web-app-status-bar-style" content="default" /> 
    <link rel="shortcut icon" href="favicon.ico" /> 

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 

    <script type="text/javascript" src="cordova-2.1.0.js"></script> 
    <script type="text/javascript" src="childbrowser.js"></script> 

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 

    <script type="text/javascript"> 

     document.addEventListener("deviceready", loaded, false); 

     function loaded() 
     { 
      if (console) 
      { 
       console.log("cordova loaded"); 
      } 
     } 

     function showExternalPage() 
     { 
      if (console) 
      { 
       console.log("in show pmt page"); 
      } 

      Cordova.exec("ChildBrowserCommand.showWebPage", "http://www.google.com/"); 
     } 

     </script> 

</head> 

<body> 

    <div data-role="page" id="myExternalLauncherPage" data-theme="a"> 

     <div data-role="content"> 

      <ul data-role="listview" data-inset="true"> 

       <li> 
        <button type="submit" data-theme="b" id="launcherButton" onclick="showExternalPage()">Launch Google</button> 
       </li> 
      </ul> 

     </div> 

    </div> 

</body>