jsp布局中关于<iframe>标签的使用

本文介绍了iframe元素的基本使用方法,包括如何让iframe自适应大小、在iframe页面中通过JavaScript操作父窗口内容,以及如何设置链接目标避免画中画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iframe 元素会创建包含另外一个文档的内联框架(即行内框架)。注意:在 HTML 4.1 Strict DTD 和 XHTML 1.0 Strict DTD 中,不支持 iframe 元素。

<div id="iframepage">
<iframe src="/test/common.html" align="middle" id="iframepage"  width="100%" height="435" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"  ></iframe>
</div>

1.获取iframe的自适应大小,即:不适用height和width属性,而是用onload="SetWinHeight(this);IFrameReSizeWidth(this)"方法

<script type="text/javascript">
function SetWinHeight(obj) 
{ 
	   var win=obj; 
	   if (document.getElementById("iframepage")) 
	   { 
		   if (win && !window.opera) 
		   { 
			   if (win.contentDocument && win.contentDocument.body.offsetHeight) {
				   win.height = win.contentDocument.body.offsetHeight + 25;
				   } 
			   else if(win.Document && win.Document.body.scrollHeight) {
				   win.height = win.Document.body.scrollHeight + 25;
			   } 
			   
		   } 
	   } 
} 

function IFrameReSizeWidth(obj) {
	   var win=obj; 
	   if (document.getElementById("iframepage"))
	   { 
		   if (win && !window.opera) 
		   { 
			   if (win.contentDocument && win.contentDocument.body.offsetWidth) {
				   win.width = win.contentDocument.body.offsetWidth;
				   } else if(win.Document && win.Document.body.scrollWidth) {
				   win.width = win.Document.body.scrollWidth;
			   } 
			   
		   } 
	}

}
</script>

2.在iframe页面中用js操作父窗口的内容

window.parent.document.getElementById('mulufirst').innerHTML=$(this).text();


3.iframe中的链接在父窗口中不出现”画中画“,即如何操作它的类似于target的属性:在location前加上window.top/parent/blank.....等,如果是单纯的<a>标签,直接设置target属性即可;

<a class="search_btn"   id="searchAnswer">搜索答案</a>

<script>
	$(function() {
		var searchKey = $("#searchAsk");

		$("#searchAnswer")
				.click(
						function() {
							if (searchKey.val() == ""
									|| searchKey.val() == "请输入你的问题?") {
								window.top.location.href = "http://baidu.com";
							} else {
								var asktitle = escape(searchKey.val());
								window.top.location.href = "http://hao123.com?key=121";
							}

						});
		
</script>

如果需要设成_blank属性的话,不能直接用window.blank.location.href

window.top.location.href = "http://baidu.com";
window.open("http://baidu.com","_blank");



我发你一个导航页代码,你协调好它们之间的关系,并且用easyui美化它们。 导航页ProNv:“<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>商品基本信息管理系统</title> </head> <frameset rows="15%,*" cols="*" frameborder="yes" border="5" framespacing="0"> <frame src="<%=request.getContextPath()%>/prohome/top.jsp" name="topFrame" scrolling="NO" noresize > <frameset cols="25%,*" frameborder="yes" border="5" framespacing="0"> <frame src="<%=request.getContextPath()%>/prohome/left.jsp" name="leftFrame" scrolling="YES" noresize> <frame src="<%=request.getContextPath()%>/prohome/welcome.jsp" name="mainFrame"> </frameset> </frameset> <noframes> <body>您的浏览器无法处理框架!</body> </noframes> </html> ” 左页面:“<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="javax.servlet.http.HttpServletRequest"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td><a href="../proinfomgmt/ProInfolist.jsp" target="mainFrame">商品基本信息列表</a></td> </tr> <tr> <td><a href="../proinfomgmt/QueryProInfoSelectVal.jsp" target="mainFrame">商品列表查询</a></td> </tr> <tr> <td><a href="../proinfomgmt/QueryProInfo.jsp" target="mainFrame">查询商品基本信息</a></td> </tr> <tr> <td><a href="../proinfomgmt/QueryProInfoMultConds.jsp" target="mainFrame">多条件查询学生基本信息</a></td> </tr> <tr> <td><a href="../proinfomgmt/AddProInfo.jsp" target="mainFrame">添加商品基本信息</a></td> </tr> <tr> <td><a href="../proinfomgmt/ProInfolistforModi.jsp" target="mainFrame">修改或删除商品基本信息</a></td> </tr> <tr> <td><a href="../invinfomgmt/Invinfolist.jsp" target="mainFrame">库存信息列表</a></td> </tr> <tr> <td><a href="../invinfomgmt/QueryInvInfoMultConds.jsp" target="mainFrame">多条件查询库存信息</a></td> </tr> <tr> <td><a href="../invinfomgmt/QueryInvInfoSelectVal.jsp" target="mainFrame">库存列表查询</a></td> </tr> <tr> <td><a href="../Inbinfomgmt/AddInbInfo.jsp" target="mainFrame">添加入库信息</a></td> </tr> <tr> <td><a href="../Inbinfomgmt/InbInfolistforModi.jsp" target="mainFrame">修改或删除入库信息</a></td> </tr> <tr> <td><a href="../Outinfomgmt/AddOutInfo.jsp" target="mainFrame">添加出库信息</a></td> </tr> <tr> <td><a href="../Outinfomgmt/OutInfolistforModi.jsp" target="mainFrame">修改或删除出库信息</a></td> </tr> <tr> <td><a href="../userinfomgmt/UserInfolistforModi_1.jsp" target="mainFrame">员工重置密码</a></td> </tr> <% String operator_id = (String) request.getSession().getAttribute("user"); //下一句不能用== if ("U202340848".equals(operator_id)) { %> <tr> <td><a href="../userinfomgmt/AddUserInfo.jsp" target="mainFrame">管理员添加员工信息</a></td> </tr> <tr> <td><a href="../userinfomgmt/UserInfolist_1.jsp" target="mainFrame">管理员查看员工列表</a></td> </tr> <tr> <td><a href="../userinfomgmt/UserInfolistforModi.jsp" target="mainFrame">管理员重置员工密码和删除员工信息</a></td> </tr> <tr> <td><a href="../userinfomgmt/QueryUserInfoSelectVal.jsp" target="mainFrame">管理员通过列表查询员工信息</a></td> </tr> <tr> <td><a href="../userinfomgmt/QueryUserInfo.jsp" target="mainFrame">管理员精准查询员工信息</a></td> </tr> <% } if ("".equals(operator_id)) { System.out.println("无session");//测试用 %> <%} %> </table> </body> </html> ” 主页面:“<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>商品基本信息管理</title> </head> <body style="background: url(../image/welcome.jpg); background-size:40% 100%; background-attachment: fixed; background-repeat:no-repeat; background-position:center center"> </body> </html> ” 顶端页面:“<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>商品基本信息管理系统</title> </head> <body> <h1 align="center">商品基本信息管理系统</h1> <div align="right"><a href="<%=request.getContextPath()%>/UserLogousvlt">注销</a></div> </body> </html> ”
最新发布
07-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值