如何使用childBrowser的phonegap应用程序

时间:2012-09-29 16:26:34

标签: jquery css cordova iframe childbrowser

我需要在我的phonegap应用程序中显示一个网页,并能够应用一个新的css文件来覆盖显示 - 或者在没有CSS的情况下有不同的方法吗?

我知道这必须是可能的,因为如果我用mozilla在我的桌面上打开网页,我可以使用firebug来调整css以获得我想要的外观。我不能使用iframe,因为我需要做的唯一改变是尺寸。我需要将它缩小一点,因为我不想在移动应用程序中滚动。这是代码我有一种感觉,这仍然可能无法工作,因为我认为我应该启用Flash(我试图加载的页面是一个实时流)但我想看看这些更改首先做什么

的index.html:

<!DOCTYPE html>
<html>
<head>
<title>Hello Phonegap</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    <meta charset="utf-8">


    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="theme.css" />
    <link rel="stylesheet" href="theme.min.css" />
    <script type="text/javascript" charset="utf-8" src="childbrowser.js"></script>
    <script type="text/javascript">




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

    function onDeviceReady()
    {
        // do your thing!
        navigator.notification.alert("Phonegap is ready")
    }

    </script>
<link href="jquery-mobile/jquery.mobile.structure-1.0.min.css" rel="stylesheet" type="text/css">
</head>
<body onload="onBodyLoad()">
    <!-- Home -->
<div data-role="page" id="page1">
        <div data-role="content">
          <ul class="ui-btn-up-a" data-role="listview" data-theme="a">
            <li><a href="#">Page</a></li>
            <li><a href="#">Page</a></li>
            <li><a href="#">Page</a></li>
            <li class="ui-bar-a"><a href="#" onClick= "window.plugins.childBrowser.showWebPage('http://www.google.com');">child</a></li>
          </ul>

        </div>

    </div>
  </div>

config.xml中

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id        = "com.phonegap.example"
version   = "1.0.0">

<name>PhoneGap Build Application</name>

<description>
A simple PhoneGap Build application.
</description>

<author href="https://example.com" email="you@example.com">
Your Name
</author>
<gap:plugin name="ChildBrowser" />
<access origin="*" />

</widget>

2 个答案:

答案 0 :(得分:0)

添加新的css文件使用以下内容:

var obj=document.createElement("link");
obj.setAttribute("rel", "stylesheet")
obj.setAttribute("type", "text/css")
obj.setAttribute("href", your_css_file)
obj.setAttribute("id", id_to_remove_it_later);
document.getElementsByTagName("head")[0].appendChild(obj);

希望有所帮助

答案 1 :(得分:0)

你在res / config.xml中的

您必须添加新功能

<feature name="ChildBrowser" > <plugin name="ChildBrowser" value="com.phonegap.plugins.childBrowser.ChildBrowser"/> </feature>

并删除<gap:plugin name="ChildBrowser" />


您可以在此代码中测试(HTML)

<div onclick='window.plugins.childBrowser.showWebPage("http://cran.r-project.org/doc/manuals/R-intro.pdf",
{ showLocationBar: true, showNavigationBar: true, showAddress: true});'><b>test222</b></div>   

<div onclick='window.plugins.childBrowser.showWebPage("http://cran.r-project.org/doc/manuals/R-intro.pdf",
{ showLocationBar: true, showNavigationBar: true, showAddress: false});'><b>test222</b></div>   

<div onclick='window.plugins.childBrowser.showWebPage("http://cran.r-project.org/doc/manuals/R-intro.pdf",
{ showLocationBar: true, showNavigationBar: false, showAddress: true});'><b>test222</b></div>   

<div onclick='window.plugins.childBrowser.showWebPage("http://cran.r-project.org/doc/manuals/R-intro.pdf",
{ showLocationBar: true, showNavigationBar: false, showAddress: false});'><b>test222</b></div>   

<div onclick='window.plugins.childBrowser.showWebPage("http://cran.r-project.org/doc/manuals/R-intro.pdf",
{ showLocationBar: false, showNavigationBar: true, showAddress: false});'><b>test222</b></div>