js跳转页面与打开新窗口的方法
1.超链接<a href="https://blog.youkuaiyun.com/wang20y8" title="打开一个新页面" ">同当前窗口中打开窗口</a>
等效于js代码
window.location.href="https://blog.youkuaiyun.com/wang20y8"; //在同当前窗口中打开窗口
window.top.location.href="https://blog.youkuaiyun.com/wang20y8"; //在同当前窗口中打开窗口
2.超链接<a href="https://blog.youkuaiyun.com/wang20y8" title="打开一个新页面" target="_blank">弹出新页面打开</a>
等效于js代码
window.open("https://blog.youkuaiyun.com/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>");
本文介绍了如何使用JavaScript(JS)和Java Server Pages(JSP)进行页面跳转及打开新窗口的操作。通过超链接和JS代码示例,展示了在当前窗口中打开页面、新建窗口打开页面的方法。同时,给出了在控制器中实现页面跳转的示例代码。
1684

被折叠的 条评论
为什么被折叠?



