问题:
在邮件系统中写新邮件或者回复邮件时,我们一般会在主界面上直接编辑邮件内容,如果邮件还没有编辑完成,我们却需要查看其他邮件,这时就要开启一个新窗口保留未编辑完的邮件内容。
解决方案:


//1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>1</title>
<script type="text/javascript">
function editInNewWin()
{
var win = window.open("2.html","_blank","width=400,height=300");
}
</script>
<style type="text/css">
#editor {width: 300px}
#title, #editor textarea{width: 100%;height: 80%}
</style>
</head>
<body>
<form action=#>
<div id=editor>
标题:<input type="text" id="title">
内容:<textarea cols=30 rows=5 id=content></textarea>
<input type=button value="提交">
<input type=button value="在新窗口中编辑" onclick="editInNewWin()">
</div>
</form>
</body>


//2.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>2</title>
<script type="text/javascript">
function init()
{
var oldPage = window.opener;
if(!parent) return;
$("title").value = oldPage.document.getElementById("title").value;
$("content").value = oldPage.document.getElementById("content").value;
}
function $(id){
return document.getElementById(id);
}
</script>
<style type="text/css">
#editor {width: 300px}
#title, #editor textarea{width: 100%;height: 80%}
</style>
</head>
<body onload="init()">
<form action="#">
<div id="editor">
标题:<input type="text" id="title">
内容:<textarea cols=30 rows=5 id=content></textarea>
<input type=button value="提交">
</div>
</form>
</body>
</html>