js跳转页面与打开新窗口的方法
1.超链接<a href="https://blog.csdn.net/wang20y8" title="打开一个新页面" ">同当前窗口中打开窗口</a>
等效于js代码
window.location.href="https://blog.csdn.net/wang20y8"; //在同当前窗口中打开窗口
window.top.location.href="https://blog.csdn.net/wang20y8"; //在同当前窗口中打开窗口
2.超链接<a href="https://blog.csdn.net/wang20y8" title="打开一个新页面" target="_blank">弹出新页面打开</a>
等效于js代码
window.open("https://blog.csdn.net/wang20y8"); //在另外新建窗口中打开窗口
controller:
HttpServletResponse response
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<script language=\"javascript\">if(window.opener==null){window.top.location.href=\"" + url
+ "login\";}else{window.opener.top.location.href=\"" + url
+ "login\";window.close();}</script>");