Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在弹出窗口JS上侦听GET回调_Javascript_Dom Events - Fatal编程技术网

Javascript 在弹出窗口JS上侦听GET回调

Javascript 在弹出窗口JS上侦听GET回调,javascript,dom-events,Javascript,Dom Events,我有一个名为REDSYS的支付平台,当支付成功时,它会重定向到回调URL(由我定义)。向该URL发送一个GET查询,其中包含付款结果,以检查其是否正确 现在我正在做的是重定向到我的web“”。加载时,如果消息为“isCallBackResult”,则此页面将订阅消息事件,并使用get查询对其进行回答 打开弹出窗口的主页以500毫秒的间隔向弹出窗口发送消息“isCallBackResult?”,并订阅一个消息事件,该事件将是弹出回答消息中的get查询 它工作正常,但我知道这不是最好的方法。有人能以

我有一个名为REDSYS的支付平台,当支付成功时,它会重定向到回调URL(由我定义)。向该URL发送一个GET查询,其中包含付款结果,以检查其是否正确

现在我正在做的是重定向到我的web“”。加载时,如果消息为“isCallBackResult”,则此页面将订阅消息事件,并使用get查询对其进行回答

打开弹出窗口的主页以500毫秒的间隔向弹出窗口发送消息“isCallBackResult?”,并订阅一个消息事件,该事件将是弹出回答消息中的get查询

它工作正常,但我知道这不是最好的方法。有人能以其他方式帮助我实现吗

主页代码:

    const host =
        window.location.protocol +
        '//' +
        window.location.hostname +
        (window.location.port ? ':' + window.location.port : '');

    let newWin = window.open(
        'about:blank',
        'Redirigiendo...',
        'width=800,height=700'
    );

    newWin.addEventListener(
        'load',
        function() {
            //Generated POST form wich redirect to the payment page
            var form = newWin.document.createElement('form');
            form.setAttribute('method', 'post');
            form.setAttribute('action', redsysForm.url);

            //API data
            let params = {
                Ds_SignatureVersion: redsysForm.body.Ds_SignatureVersion,
                Ds_MerchantParameters: redsysForm.body.Ds_MerchantParameters,
                Ds_Signature: redsysForm.body.Ds_Signature
            };

            for (var i in params) {
                if (params.hasOwnProperty(i)) {
                    var input = newWin.document.createElement('input');
                    input.type = 'hidden';
                    input.name = i;
                    input.value = params[i];
                    form.appendChild(input);
                }
            }
            newWin.document.body.appendChild(form);

            form.submit();

            let interval = setInterval(function() {
                if (newWin.closed) clearInterval(interval);
                console.log('interval');
                newWin.postMessage({ type: 'isCallBackResult?' }, host);
            }, 500);

            window.addEventListener('message', function handler(event) {
                if (event.data.type == 'callBackResult') {
                    clearInterval(interval);
                    event.source.close();
                    const result = redsys.processNotification(event.data.data);
                    window.removeEventListener('message', handler);
                }
            });
        },
        false
    );
回调页代码

   const host =
      window.location.protocol +
      '//' +
      window.location.hostname +
      (window.location.port ? ':' + window.location.port : '');

    window.addEventListener('message', event => {
        if (event.data.type == 'isCallBackResult?') {
            event.source.postMessage(
                {
                    type: 'callBackResult',
                    data: this.$route.query //The GET Query by VUE
                },
                host
            );
        }
    });