【问题标题】:How to use childBrowser for phonegap app如何将 childBrowser 用于 phonegap 应用程序
【发布时间】:2014-07-16 17:07:03
【问题描述】:

我需要在我的 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>

【问题讨论】:

  • 我准备挂了,哈哈。任何帮助都会很棒!
  • 那么您是否尝试过使用 css 调整包含 childBrowser 的元素的大小?
  • 不,我没有,但那行得通吗?我需要更改在 childbrowser 中查看的网页的大小。我知道 IE 有 iframe 的缩放属性,它们有什么相似之处吗?
  • 试一试,但正如您所知,您无法更改 3rd 方 iframe 中的内容,我怀疑这就是这里发生的事情。

标签: jquery css cordova iframe childbrowser


【解决方案1】:

要添加新的 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);

希望对你有帮助

【讨论】:

    【解决方案2】:

    在你的 res/config.xml 中

    你必须添加新功能

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

    并删除&lt;gap:plugin name="ChildBrowser" /&gt;


    您可以在此代码中进行测试 (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> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      相关资源
      最近更新 更多