码迷,mamicode.com
首页 > 其他好文 > 详细

利用form的target属性屏蔽url跳转

时间:2014-08-18 23:39:33      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:form   target   

target:

规定在何处打开 action URL。

关键点:

让target指向隐藏的iframe


demo:

form.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function doSave(){
		var param = "?method=add";
		testForm.action='handler.jsp' + param ;
		testForm.submit();
	}
</script>

</head>
<body>
<form id="testForm" name="testForm" method="post" target="sub_frame">
id:<input type="text" name="id"><input type="button" value="提交" onclick="doSave();">
<iframe id="sub_frame" name="sub_frame" height="0" width="0" frameborder="0" marginheight="0" marginwidth="0" ></iframe>
</form>
<br/>id值:
<input id="content" name="content" type="text">
</body>
</html>

handler.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String method=request.getParameter("method");
if("add".equals(method)){
	String id =request.getParameter("id");
	out.println("<script type='text/javascript'>");
	out.println("parent.document.getElementById('content').value='"+id+"';");
	out.println("</script>");
}
%>



利用form的target属性屏蔽url跳转,布布扣,bubuko.com

利用form的target属性屏蔽url跳转

标签:form   target   

原文地址:http://blog.csdn.net/wobendiankun/article/details/38667379

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!