I’m trying to open new window and send form data
with javascript and jquery-1.8.3. But, It’s not woriking.
This is source code.
<a href="#" onclick="printPage()">Print this</a>
<script type="text/javascript" src="/common/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function printPage(){
var form = $("<form method='post' action='/common/print.jsp' target='printWindow'></form>");
var input = $("<input type='hidden' name='view'/>");
input.val($("#ctn").html());
form.append(input);
var printWindow = window.open(form.attr("action"), "printWindow", "width=700px,height=800px");
form.submit();
}
</script>
window was opened. But request.getParameter("name") is null.
Here is /common/print.jsp page
<%@ page contentType="text/html; charset=utf-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<div id="ctn">
<%
out.print(request.getParameter("view"));
%>
</div>
What’s the problem in this code?
Are you faking an ajax call 😉
Better you do something like this: