在frameset,frame,iframe中如何操作其他框架中的页面以及如何刷新框架中的页面...

以你之姓@ 2022-04-15 02:10 311阅读 0赞

frameset,frame,iframe可以让我们很好的布局整个web页面。

每个web工程没有不用到这些的,那在frameset,frame,iframe中如何操作其他框架中的页面以及如何刷新框架中的页面?

这个是很常用的,如果你对这个不熟悉,那你只能算是个会写java后台代码的菜鸟,

前台的页面控制很能看出程序员的水平。

先看一个实际项目中的例子:

main.jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. %>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>客户服务中心系统</title>
  10. <link rel="shortcut icon" href="<%=path%>/resource/images/favicon.ico" type="image/x-icon"/>
  11. </head>
  12. <frameset rows="124,*,36" frameborder="no" border="0" framespacing="0">
  13. <frame src="../jsp/hd/top.jsp" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
  14. <frame src="../jsp/hd/home/homeframe.html" name="mainFrame" id="mainFrame" title="mainFrame" />
  15. <frame src="../jsp/hd/foot.jsp" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomFrame" title="bottomFrame" />
  16. </frameset>
  17. <noframes>
  18. <body>
  19. </body></noframes>
  20. </html>

homeframe.html

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. <title>框架</title>
  5. </head>
  6. <frameset cols="260,*" frameborder="no" border="0" framespacing="0" id="lrsplitframe" name="lrsplitframe">
  7. <frame src="homeleft.jsp" id="homeleft" name="homeleft" scrolling="no" noresize="noresize" noresize/>
  8. <frame src="homeright.jsp" id="homeright" name="homeright" scrolling="no" noresize/>
  9. </frameset>
  10. <noframes><body>
  11. </body></noframes>
  12. </html>

如果在homeright签入一个框架页面:
module.jsp

  1. <%@ taglib uri="/struts-tags" prefix="s"%>
  2. <%
  3. String otherParam = request.getParameter("otherParam");
  4. if(otherParam == null){
  5. otherParam = "";
  6. }
  7. %>
  8. <html>
  9. <head>
  10. <title></title>
  11. </head>
  12. <frameset id="MAINFRAMESET" rows="300,10,*" border="0" frameborder="0" frameSpacing="0">
  13. <frameset rows="0pt,*" frameborder="NO" border="0" framespacing="0">
  14. <frame src='<%=request.getContextPath()%>/mainMenu.action?parentMenuId=<%=request.getParameter("parentMenuId")%>&otherParam=<%=otherParam%>' id="MAINMENU" name="MAINMENU" scrolling="NO" noresize>
  15. <frame src="" name="MAINCONTENT" noresize >
  16. </frameset>
  17. <frame id="MENUBAR" name="MENUBAR" src="<%=request.getContextPath()%>/jsp/layout/menubar.jsp" noresize scrolling="no" frameborder="0" pos="1">
  18. <frameset rows="35,*" frameborder="NO" border="0" framespacing="0" id="CONTENTFRAMESET">
  19. <frame src='<%=request.getContextPath()%>/subMenu.action?parentMenuId=<%=request.getParameter("parentMenuId")%>&otherParam=<%=otherParam%>' id="SUBMENU" name="SUBMENU" scrolling="NO" noresize>
  20. <frame src="" name="SUBCONTENT">
  21. </frameset>
  22. </frameset>
  23. <noframes><body>
  24. </body></noframes>
  25. </html>

整体的布局可以用一张图来看,这样更清楚:

1348108462_8719.JPG

上面的MAINCONTENT中嵌入listphonebook.jsp
我们想在listphonebook.jsp中调用其他页面的方法或者刷新某个frame中的页面应该怎么做呢?

比如homeleft.jsp中有个方法:
function gg(){
alert(“gg”);
}

方法1:使用parent跳出本框架再找其他框架。

一,刷新listphonebook.jsp

当然也可以window.location.reload();
不过这个刷新会有IE的提示框弹出,效果不是很好。
所以把右面所有页面刷新
parent.window.parent.window.frames[1].window.location.reload();

刷新左面homeleft.jsp
parent.window.parent.window.frames[0].window.location=”xxx.jsp”;
parent.window.parent.window.frames[0].window.location.reload();
二,调用homeleft.jsp中的方法
parent.window.parent.window.frames[0].gg();

parent.window是homeright
parent.window.parent.window是mainFrame
parent.window.parent.window.frames[0]是homeleft.jsp
这样就可以调用这个页面的方法gg();

方法2:使用top跳到本页面的顶层框架,然后一层层按从外向里的顺序找到你要的页面。

一,刷新listphonebook.jsp
那在此页面可以
top.mainFrame.homeright.location=”<%=path%>/jsp/layout/module.jsp?parentMenuId=hd_phonebook”;
或者
top.mainFrame.homeright.location.reload();
刷新左面homeleft.jsp
top.mainFrame.homeleft.location=”xxx.jsp”;
或者
top.mainFrame.homeleft.location.reload();
二,调用homeleft.jsp中的方法
top.mainFrame.homeleft.window.gg();

发表评论

表情:
评论列表 (有 0 条评论,311人围观)

还没有评论,来说两句吧...

相关阅读