简体   繁体   English

点击打开弹出窗体,然后提交下载并关闭它! 怎么样?

[英]On click open popup with form and then on submit download and close it! How?

Here is what I am trying to do 这是我想要做的

  1. Click on download link. 点击下载链接。
  2. On click Popup will open. 单击弹出窗口将打开。 Contact form is in the popup. 联系表单在弹出窗口中。
  3. On submit button send mail and auto start download of PDF file. 在提交按钮发送邮件和自动开始下载PDF文件。
  4. At the same time of starting of download close the popup without redirecting to any page. 在开始下载的同时关闭弹出窗口而不重定向到任何页面。

I tried using .click() window.open() 我尝试使用.click() window.open()

$('#theForm').submit(function(){

            event.preventDefault();

            var $form = $( this ),

            url = $form.attr( 'action' );

            var posting = $.post( url, { name: $('#name').val(), name2: $('#name2').val() } );

            /* Alerts the results */

            posting.done(function( data ) {

                $(".modal-backdrop.fade.in").css("display", "none");

                document.getElementById("anchorID").click();

                $("#pdfdownload").css("display", "none");


            });

});

I am able to open download link using this code but browser blocks it as a popup. 我可以使用此代码打开下载链接,但浏览器将其作为弹出窗口阻止。 Please help me to find the solution. 请帮我找到解决方案。

Thank You 谢谢

Browsers block popup windows because they are typically annoying and employed by malicious advertisements. 浏览器阻止弹出窗口,因为它们通常很烦人并被恶意广告使用。

The better way to go about this is to use a modal window , which is basically the same as a popup, but instead of being a separate browser window, it's simply a separate element within the page that hovers above other content. 更好的方法是使用模态窗口 ,它基本上与弹出窗口相同,但它不是一个单独的浏览器窗口,而是页面中的一个单独元素,悬停在其他内容之上。

Use bootstrap modal: 使用bootstrap模式:

<script>
function send(){
var  name = $("input#name").val();
var  email = $("input#email").val();
$.ajax({
        type: "POST",
        url: "send.php", //your mailing code is place on send.php
        data:'name='+ name'&email='+email,
        success: function(data){
        $('#download').modal('hide');
        window.location.href='uploads/yourpdf.pdf'; //your file location        
            });
        }
}
</script>

The html code HTML代码

<a href="#" class="btn btn-primary" data-toggle="modal" data-target="#download">Download</a>

<!-- modal for download and contact -->
<div class="modal fade" id="download" role="dialog" >
<div class="modal-dialog" >
<div class="modal-content">
<!-- Your contact form goes here --->
<form method="post">
<input type="text" id="name" placeholder="name">
<input type="text" id="email" placeholder="email">
<button onclick="send();">send</button>
</form>
</div></div></div>

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

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