[英]On click open popup with form and then on submit download and close it! How?
Here is what I am trying to do 这是我想要做的
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.