提交表单到弹出窗口 Submit a form into a popup (含实例)

实例目的:一些网站不允许被包含在iframe中(例如paypal standard),为了实现让用户仍然留在本站的目的,下面的实例可供参考。

 

方法一: HTML的方式 DEMO

<form id="paypal-payment-form" name="paypal-payment-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="POPUPW"
                  onsubmit="POPUPW = window.open('about:blank','POPUPW','width=900,height=700,scrollbars=yes,resizable=yes');">
                <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="business" value="gotoinquire@gmail.com">
                <input type="hidden" name="item_name" value="Donate to Developer">
                <input type="hidden" name="item_number" value="for-iKS">
                <input type="hidden" name="amount" value="">
                <input type="hidden" name="currency_code" value="USD">
                <input type="hidden" name="bn" value="PP-BuyNowBF">
                <input type="hidden" name="first_name" value="Your First Name">
                <input type="hidden" name="last_name" value="Your Last Name">
                <input type="hidden" name="email" value="Your Email">
                <input type="submit" name="submit" value="Click Paypal Button 点击这里">
            </form>

 

方法二: Javscript的方式 DEMO

<script>
function target_popup(form) {
    window.open('about:blank','POPUPW','width=900,height=700,scrollbars=yes,resizable=yes');
    form.target = 'POPUPW';
}
</script>
<form id="paypal-payment-form" name="paypal-payment-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="target_popup(this)">
                <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="business" value="gotoinquire@gmail.com">
                <input type="hidden" name="item_name" value="Donate to Developer">
                <input type="hidden" name="item_number" value="for-iKS">
                <input type="hidden" name="amount" value="">
                <input type="hidden" name="currency_code" value="USD">
                <input type="hidden" name="bn" value="PP-BuyNowBF">
                <input type="hidden" name="first_name" value="Your First Name">
                <input type="hidden" name="last_name" value="Your Last Name">
                <input type="hidden" name="email" value="Your Email">
                <input type="submit" name="submit" value="Click Paypal Button 点击这里">
            </form>

 

方法三: 链接的方式 , DEMO

<a href="javascript:OpenWindowWithPost('https://www.paypal.com/cgi-bin/webscr','width=1000,%20height=600,%20left=100,%20top=100,%20resizable=yes,%20scrollbars=yes','gotoinquire@gmail.com','Paypal')">Click Paypal Button 点击这里</a>

        <script>
            function OpenWindowWithPost(url, windowoption, name)
            {
                var params = { 'cmd' : '_xclick',  'item_name' : 'Donate to Developer',  'item_number' : 'for-iKS',  'currency_code' : 'USD',  'bn' : 'PP-BuyNowBF',  'first_name' : 'Your First Name', 'last_name' : 'Your Last Name', 'email' : 'Your Email', 'amount' : '', 'business': 'gotoinquire@gmail.com' };

                var form = document.createElement("form");
                form.setAttribute("method", "post");
                form.setAttribute("action", url);
                form.setAttribute("target", name);
                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);
                //note I am using a post.htm page since I did not want to make double request to the page
                //it might have some Page_Load call which might screw things up.
                window.open("post.htm", name, windowoption);
                form.submit();
                document.body.removeChild(form);
            }
        </script>

 

 

本文:提交表单到弹出窗口 Submit a form into a popup

Leave a Reply