您的位置:首页 > 运维架构

window.open实现post提交

2010-01-23 16:51 316 查看
主要用到form中的target属性以及onsubmit事件的触发:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title></title>
<script type="text/javascript">
<!--
var sunwin;
function migClick() {
sunwin = window.open('main.jsp', 'subWin', 'height=800, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no');
sunwin.focus();
}
function postWin() {
obj = document.getElementById('logonForm');
obj.action = url;//在此处设置你要跳转的url
obj.fireEvent('onsubmit');
obj.submit();
}
// -->
</script>
</head>
<body>
<form id='logonForm' method='post' target='subWin' onsubmit='migClick();'>
User:<input type='text' id='username' name='username' value='admin'></input><br/>
Password:<input type='password' id='password' name='password' value='password'></input><br/>
<button id='btn_submit' onclick='postWin();'>Login</button>
</form>
</body>
</html>


该方法只适用与IE,firfox不支持fireEvent方法调用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: