如何使用InAppBrowser使用window.open()发送表单数据

时间:2016-04-18 04:52:45

标签: javascript angularjs cordova inappbrowser

我要求我需要使用 window.open()发送表单数据。我将把PayU资金整合到Ionic和AngularJS应用程序中,我需要使用 InAppBrowser Cordova插件从window.ope()发送一些表单数据,但是我无法发送表单数据。

在我的 app.js

中编写代码
    var example = angular.module('starter', ['ionic', 'ngSanitize']);
    example.run(function($ionicPlatform, $timeout) {
    $ionicPlatform.ready(function() {
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            StatusBar.styleDefault();
        }
    });
    });
    example.controller("ExampleController", ['$scope', '$interval', function($scope, $interval) {
    $scope.myHTML = 'Check out my programming <a href="https://www.thepolyglotdeveloper.com">blog</a> while you are here';
    $scope.testmethod = function() {
        onDeviceReadyEWEWE();
    }
    }]);
    // Global InAppBrowser reference
     var iabRef = null;

    function iabLoadStart(event) {
    var winName = 'MyWindow';
    //var winURL='https://test.payu.in/_payment.php';
    var winURL = 'https://test.payu.in/_payment';
    // var winURL='https://test.payu.in/merchant/postservice.php?form=2';
    var windowoption = 'resizable=yes,height=600,width=800,location=0,menubar=0,scrollbars=1';
    //var params = { 'param1' : '1','param2' :'2'};  
    var params = {
        'key': 'gtKFFx',
        'txnid': 'mdd0sss9023',
        'amount': '100',
        'productinfo': 'oxygenconcentrator',
        'firstname': 'test',
        'email': 'test@gmail.com',
        'phone': '9000024100',
        'surl': 'https://payu.herokuapp.com/success',
        /*  'Furl' :'https://www.payumoney.com/mobileapp/payumoney/failure.php', */
        'Furl': 'https://payu.herokuapp.com/failure',
        'Hash': '9feaefa45b5b68c7091f7f1ff513183f3fca5b23b47d47d760c285c8ad2d5f9fd1ec9514f2bad5d3672b6cb9138af5dd5350a5cf1e87c6f20ca26817ee02ae77'
    };
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", winURL);
    form.setAttribute("target", winName);
    for (var i in params) {
        if (params.hasOwnProperty(i)) {
            var input = document.createElement('input');
            input.type = 'hidden';
            input.name = i;
            input.value = params[i];
            form.appendChild(input);
        }
     }
    document.body.appendChild(form);
    // window.open('', winName,windowoption);
    form.target = winName;
    console.log(form.action);
    form.submit();
    alert(event.type + ' - ' + event.url);
    }

    function iabLoadStop(event) {
    alert(event.type + ' - ' + event.url);
    }

    function iabLoadError(event) {
    alert(event.type + ' - ' + event.message);
    }

    function iabClose(event) {
    alert(event.type);
    iabRef.removeEventListener('loadstart', iabLoadStart);
    iabRef.removeEventListener('loadstop', iabLoadStop);
    iabRef.removeEventListener('loaderror', iabLoadError);
    iabRef.removeEventListener('exit', iabClose);
    }
    // device APIs are available

    function onDeviceReadyEWEWE() {
    //form.submit();   
    var options = {
        location: 'yes',
        clearcache: 'yes',
        toolbar: 'yes',
        closebuttoncaption: 'DONE?'
    };
    iabRef = window.open('https://test.payu.in/_payment', '_blank', options);
    iabRef.addEventListener('loadstart', iabLoadStart);
    iabRef.addEventListener('loadstop', iabLoadStop);
    iabRef.addEventListener('loaderror', iabLoadError);
    iabRef.addEventListener('exit', iabClose);
     }

并在我的 index.html

    <!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>

        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">

        <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
        <link href="css/ionic.app.css" rel="stylesheet">
        -->

        <!-- ionic/angularjs js -->
        <script src="lib/ionic/js/ionic.bundle.js"></script>

        <!-- cordova script (this will be a 404 during development) -->
        <script src="cordova.js"></script>

        <!-- your app's js -->
        <script src="js/app.js"></script>

    </head>
    <body ng-app="starter">
        <ion-pane>
            <ion-header-bar class="bar-stable">
                <h1 class="title">Ionic Blank Starter</h1>
            </ion-header-bar>
            <ion-content ng-controller="ExampleController">
            <a href="http://www.google.com">Testing</a>
            <p ng-bind-html="myHTML"></p>

            <button ng-click="testmethod()">button</button>

        </ion-content>
        </ion-pane>
    </body>
</html>

所以请帮我解释如何在window.open();

中使用URL发送表单数据

编辑后:

最终将Inappbrowser集成到我的Ionic应用程序并破解了解决方案。请找到适用于混合应用的PayU Money Integration的网址PayUmoneyIntegartion

0 个答案:

没有答案