1.
重点是对层的判断:
被框架加载的页面不能放入最顶层top层,
所以可以通过判断top层
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <title>标题页</title> 7 <script language="javascript"> 8 if(self!=top){ 9 top.location=self.location; //判断是否是最顶层,不是则将当前页设置为最顶层 10 } 11 </script> 12 </head> 13 <body> 14 AAAAAAAAAA 15 </body> 16 </html>
2.
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 BBBB 11 <iframe src="1.jsp"></iframe> 12 </body> 13 </html>