【问题标题】:How to pass values into inAppBrowser from ionic controller?如何将值从离子控制器传递到 inAppBrowser?
【发布时间】:2017-08-27 12:37:36
【问题描述】:

我正在用 ionic 和 cordova 开发一个混合移动应用程序。在这个应用程序中,我使用 ngCordova InAppBrowse 将 html 页面加载到应用程序中。

控制器代码:

module.controller('MyCtrl', function($cordovaInAppBrowser) {
  $scope.name="Rakesh";
  var options = {
      location: 'yes',
      clearcache: 'yes',
      toolbar: 'no'
    };

  $cordovaInAppBrowser.open('mypage.html', '_blank', options)
  .then(function(event) {
        // success
  })
  .catch(function(event) {
        // error
  });
  $rootScope.$on('$cordovaInAppBrowser:loadstart', function(e, event){
  });
  $rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event){
  });
  $rootScope.$on('$cordovaInAppBrowser:loaderror', function(e, event){
  });
  $rootScope.$on('$cordovaInAppBrowser:exit', function(e, event){
  });
});

HTML 页面 (mypage.html)

<!DOCTYPE html>
<html>
<head>
 <title>InAppBrowser - Test Page</title>
</head>
<body>
    <form name="sendParam" method="post" action="https://www.example.com/payment">
                <input type="text" id="name" name="name" value="" />
                <input type="submit" value="enter">
    </form > 
</body>
</html>

我想要什么?

我想将 MyCtrl 的 $scope.name 值设置或传递给 mypage.html name text field

【问题讨论】:

    标签: javascript html cordova ionic-framework ngcordova


    【解决方案1】:

    您不能使用 $scope 将值传递给控制器​​到 inAppBrowser,inAppBrowser 用于将外部网页打开到您的移动应用程序。

    如果您想将值从 ionic 应用程序传递到外部页面,您必须使用 URL 传递值,例如 http://html.net/page.php?paramOne=1254&paramTwo=ABC 您可以使用 PHP 或其他服务器端语言中的 $_GET['paramOne'] 来获取该值。

    或者,您可以使用下面的链接使用 javascript 获取该值 Get url parameter jquery Or How to Get Query String Values In js

    希望能帮到你:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-09
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-04-18
      • 2016-12-28
      相关资源
      最近更新 更多