JS中window.open和window.opener的使用
一、發現問題
通過A頁麵通過window.open打開一個B頁麵,B頁麵提交過後,希望局部刷新A頁麵。
二、解決問題
A頁麵
window.open(url, '','width=100,height=100,resizable=no,status=no,menubar=no,scrollbars=no');
B頁麵
<form action="BAction?method=save">
<input type="submit" value="提交" />
</form>
BAction
public void save(HttpServletRequest request,HttpServletResponse response)
{
StduentSave();
PrintWriter pw = response.getWriter();
String jsAlert = "<script>alert('操作成功');window.opener.document.getElementById('hint').innerHTML='操作成功';window.close();</script>";
pw.write(jsAlert);
pw.flush();
}
B頁麵提交給了BAction,BAction處理過後關閉了B頁麵,同時隻更新了A頁麵的提示區。
三、思考過程
除了更新某個區域的html,也可以更新表單元素:window.opener.document.getElementById('hint').value = "";
最後更新:2017-04-03 16:49:13