Iphone 使用target=";调用Childbrowser_空白";/Cordova 2.0/jQuery Mobile 1.2.0

Iphone 使用target=";调用Childbrowser_空白";/Cordova 2.0/jQuery Mobile 1.2.0,iphone,jquery-mobile,phonegap-plugins,cordova-2.0.0,childbrowser,Iphone,Jquery Mobile,Phonegap Plugins,Cordova 2.0.0,Childbrowser,我已经用jQuery Mobile 1.2为iOS构建了Cordova 2.0应用程序。框架内。我已经成功地安装了Childbrowser插件(在和中)。感谢这些好心人在这一点上的帮助 现在,我可以通过一个onclick事件直接调用Childbrowser,头部有以下javascript: <script type="text/javascript"> app.initialize(); function launchCB() { if(window.plugins.

我已经用jQuery Mobile 1.2为iOS构建了Cordova 2.0应用程序。框架内。我已经成功地安装了Childbrowser插件(在和中)。感谢这些好心人在这一点上的帮助

现在,我可以通过一个onclick事件直接调用Childbrowser,头部有以下javascript:

<script type="text/javascript">
  app.initialize();
  function launchCB() {
    if(window.plugins.childBrowser != null) {
      window.plugins.childBrowser.onLocationChange = function(loc){};
      window.plugins.childBrowser.onClose = function(){};
      window.plugins.childBrowser.onOpenExternal = function(){};
      window.plugins.childBrowser.showWebPage('http://www.google.de');
    } else {
      alert('not found');
    }
  }
</script>
先谢谢你

问候


Kieke

在您的
Cordova.plist
中,您是否有
OpenAllWhitelistURLsInWebView=YES
并且您连接的所有域(例如www.google.com、localhost)都在您的
外部主机列表中

在Xcode调试器的控制台中查看@Littm所描述的,您将看到您的链接是否被阻止,因为它们不在白名单中


你也可以检查你的system.log,
tail/var/log/system.log
在执行后是否有任何错误。

@Kieke,如果你决定取消ChildBrowser,我发现以下方法对我有效

注意:假设您使用的是PhoneGap 2.x


在你的
Cordova.plist
设置
OpenAllWhitelistURLsInWebView=YES
并设置你的
ExternalHosts
列表中,
*
就可以了。任何你想让webview不被阻止(在Safari或应用程序中查看)的内容都必须在你的
ExternalHosts
列表中

MainViewController.m
的底部添加以下代码,您可以手动将任何URL重定向到Safari,请参见
www.loadDomainInSafari.com
if
语句:

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *requestURL =[ [ request URL ] retain ];
    NSString *host = [ [ requestURL host] retain ];

    // if YES, directs to WebView
    // otherwise, takes OpenAllWhitelistURLsInWebView setting

    // if www.loadDomainInSafari.com, open in Safari by explictly stating NO.
    // otherwise take OpenAllWhitelistURLsInWebView setting of YES
    if ([host isEqualToString:@"www.loadDomainInSafari.com"]) {
        return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease] ];
    }
    [ requestURL release ];
    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}

您在控制台上有任何错误吗?谢谢您的建议,但是没有白名单拒绝。我在Externalhosts中设置了一个星号,以便允许所有请求。我认为我的代码中有错误,但控制台中没有任何错误。如果是拒绝,我会很高兴,但我会检查您提到的日志。@K请检查上面的答案,它向您展示了如何在给定if条件下手动打开Safari窗口。不需要插件。在其他地方没有看到此解决方案。谢谢!
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name = "format-detection" content = "telephone=no"/>
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width;" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Cordova</title>
    <script type="text/javascript" src="cordova-2.0.0.js"></script>
    <script type="text/javascript" src="ChildBrowser.js"></script>
    <gap:plugin name="ChildBrowser" /> <!-- latest release -->
    <script type="text/javascript" charset="utf-8" src="EmailComposer.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
      app.initialize();
      function launchCB() {
        if(window.plugins.childBrowser != null) {
          window.plugins.childBrowser.onLocationChange = function(loc){};
          window.plugins.childBrowser.onClose = function(){};
          window.plugins.childBrowser.onOpenExternal = function(){};
          window.plugins.childBrowser.showWebPage('http://www.google.de');
        } else {
          alert('not found');
        }
      }
      /*
       var args;
       cordova.exec(null, null, "EmailComposer", "showEmailComposer", [args]);
     */
   </script>
   <!-- jQuery mobile -->
   <link type="text/css" rel="stylesheet" media="screen" href="jqm/jquery.mobile-1.2.0-alpha.1.min.css">
   <link type="text/css" rel="stylesheet" media="screen" href="jqm/Changes.css">
   <script type="text/javascript" src="jqm/jquery-1.7.2.min.js"></script>
   <script>
     // for using childbrowser to open pdf on remote sites
     $(document).bind( "mobileinit", function() {
       $.mobile.allowCrossDomainPages = true;
     }
   );
   // the function i want to implement
   $(document).bind("pageinit", function() {
     onDeviceReady();
   });
   function onDeviceReady() {
     var root = this;
     cb = window.plugins.childBrowser;
     if (cb != null) {
       $('a[target="_blank"]').click(function(event) {
         cb.showWebPage($(this).attr('href'));
         event.preventDefault();
         event.stopImmediatePropagation();
         return false;
       });
     }
   }
   // don't know is this thing is right in place...
   document.addEventListener("deviceready", onDeviceReady, false);
 </script>
 <script src="jqm/jquery.mobile-1.2.0-alpha.1.min.js"></script>
</head>
<body>
  <section data-role="page" id="home" data-theme="a" data-position="fixed">
    <div data-role="header"> <!-- header -->
      <h1>Test</h1>
      <div style="position:absolute; top:0px; right:5px;">
        <a href="#about" data-transition="pop">
          <img src="images/schlange-sw.png" alt="Schlange">
        </a>
      </div>
    </div>
    <!-- /header -->
    <div data-role="content"> <!-- content -->
      <a id="domainbut" onclick='launchCB()'>Working </a>
      <a href="http://www.google.de/" target="_blank" data-role="button" data-inline="true"> not working </a>
    </div>
    <!-- content -->
    <div data-role="footer" data-theme="a" data-position="fixed"></div>
  </section>
  <section data-role="dialog" id="about" data-close-btn-text="Close This Dialog">
    <div data-role="header">
      <h1>Über</h1>
    </div>
    <div data-role="content">
      <h1 style="text-align: center;"></h1>
      <div align="center">
    </div>
    <p style="text-align: center;">The owner of this app</p>
    <button onclick="cordova.exec(null, null, 'EmailComposer', 'showEmailComposer', [args]);">Compose Email</button>
    <p>
      <a href="#home" data-role="button" data-rel="back">OK</a>
    </p>
  </div>
</section>
</body>
</html>
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *requestURL =[ [ request URL ] retain ];
    NSString *host = [ [ requestURL host] retain ];

    // if YES, directs to WebView
    // otherwise, takes OpenAllWhitelistURLsInWebView setting

    // if www.loadDomainInSafari.com, open in Safari by explictly stating NO.
    // otherwise take OpenAllWhitelistURLsInWebView setting of YES
    if ([host isEqualToString:@"www.loadDomainInSafari.com"]) {
        return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease] ];
    }
    [ requestURL release ];
    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}