简体   繁体   English

使用JavaScript函数return语句打开新页面

[英]Use JavaScript function return statement to open a new page

I'm trying to build a webpage that uses Adyen Encryption for Credit Cards. 我正在尝试建立一个使用Adyen信用卡加密的网页。 I have a form in which I ask for Credit Card data, and when the user presses submit it calls the JavaScript function. 我有一个表单,要求我提供信用卡数据,当用户按submit它将调用JavaScript函数。 Now I want to redirect that page into another one that shows the value returned with the JavaScript function. 现在,我想将该页面重定向到另一个页面,该页面显示使用JavaScript函数返回的值。 I don't know if there is a simple way to do it. 我不知道是否有简单的方法可以做到。

The index.html code is the following: index.html代码如下:

<!DOCTYPE html>
<html>

<head>
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="https://my.tidal.com/assets/javascripts/chosen.jquery.min.js"></script>
    <script src="https://my.tidal.com/assets/javascripts/payment/adyen.js"></script>
    <script src="https://my.tidal.com/assets/javascripts/payment/brazil-validate.js"></script>

    <script>
        function test(name, card, expMonth, expYear, cvc) {     

            var adyenPubKey = "10001|DCDD8889161843FF0CC8D0D904168E5B4ED5B529C685413F4F8087584F507C5158551B521B9226F7C24CAE3F9FF4B5721F39D23F1E706D3F27A4680C5A2F2B4714C1530BC1EE410B503F9487AF0F047004F4F5DA2614AF3955C25C36BA3881907063742C7687D8516176AD67570A5F0DFA682AC2B7DAD055CE00A68283B77C731E35F004A1D3FE72CE3AE52C3FA8A0E8A63C8D903E00B37DA6760C8C104332FEDD762D4BA8BDB9781C5DDF7E94E0D81529A7C01A2094E8240FB3C24C1E687AD2304A4346EBD82B5DF983806F57B2E0865143C8FEE568A6915A71044A707693C51112B80E2EC665194FD1F8FE362EF1479CCF938DDACFE9BEA56B530E81D567B3";

            var options = {};

            var cseInstance = adyen.encrypt.createEncryption(adyenPubKey, options);

            var generationTime = new Date().toISOString();  

            var cardData = {
                number : card,
                cvc : cvc,
                holderName : name,
                expiryMonth : expMonth,
                expiryYear : (expYear.length === 2) ? '20' + expYear : expYear,
                generationtime : generationTime
            };

            return cseInstance.encrypt(cardData);
        }
    </script>
</head>

<body>
    <form onsubmit="return test(document.getElementById('holderName').value,document.getElementById('number').value,document.getElementById('expiryMonth').value,document.getElementById('expiryYear').value,document.getElementById('cvc').value)" method="post">
        <input type="text" name="holderName" id="holderName" required>
        <br><br>
        <input type="text" id="number" pattern="[0-9]{16}" required>
        <br><br>
        <input type="text" id="expiryMonth" pattern="[0-9]{2}" required>
        <input type="text" id="expiryYear" pattern="[0-9]{4}" required>
        <br><br>
        <input type="text" id="cvc" pattern="[0-9]{3}" required>
        <br><br>
        <input type="submit" value="Enviar">
    </form> 
</body>

</html>

I'm not sure about your particular use case - but if you want to redirect to a new page (or request a new page from the server) and have any information carry forward to the new page - you have to send the data to the server. 我不确定您的特定用例-但是如果您想重定向到新页面(或从服务器请求新页面)并让任何信息结转到新页面上-您必须将数据发送到服务器。 The server can then send back only the particular information you want to show. 然后,服务器可以只发送回您要显示的特定信息。 (Just make sure to use HTTPS considering the nature of the data). (只要考虑到数据的性质,请确保使用HTTPS)。

If this is a single-page application then you could simply hide the form and load the next 'screen' on the current page. 如果这是一个单页面的应用程序,那么您可以简单地隐藏表单并在当前页面上加载下一个“屏幕”。 This way you could re-use the in-memory result from your form. 这样,您可以重复使用表单中的内存结果。 Just store it in an accessibly-scoped variable. 只需将其存储在可访问范围的变量中即可。

Another option may be to use local storage, but considering this is sensitive credit card information I would advise against this - encrypted or not. 另一个选择可能是使用本地存储,但是考虑到这是敏感的信用卡信息,我建议您不要这样做-是否加密。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM