iframe页面跳转多种方法 iframe跳转实例教程

发布时间:2020-12-30编辑:脚本学堂
本文介绍了iframe中页面跳转的各种方法,iframe跳转的多个实例,有需要的朋友参考下。

iframe页面跳转多种方法

iframe实现页面跳转:
 

复制代码 代码示例:
"window.location.href"、"location.href"是本页面跳转
"parent.location.href"是上一层页面跳转
"top.location.href"是最外层的页面跳转

相关阅读:iframe页面跳转的多种方法

例子:
如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写
 

复制代码 代码示例:
"window.location.href"、"location.href":D页面跳转
"parent.location.href":C页面跳转
"top.location.href":A页面跳转

如果D页面中有form的话,
 

复制代码 代码示例:
<form>: form提交后D页面跳转
<form target="_blank">: form提交后弹出新页面
<form target="_parent">: form提交后C页面跳转
<form target="_top"> : form提交后A页面跳转

关于页面刷新,D 页面中这样写:
"parent.location.reload();": C页面刷新 (当然,也可以使用子窗口的 opener 对象来
获得父窗口的对象:window.opener.document.location.reload(); )
"top.location.reload();": A页面刷新

Iframe载入页面与跳转页面的方法举例。

第一个文件 frame1.html
 

复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>第一个页面</title>
<script type="text/javascript">
function setIframe()
{
   var f=document.getElementById("newframe");
   f.style.display="inline";
   f.src="frame2.html";
}
</script>
</head>
<body>
<p>这个是第一个页面。。。。</p>
<p>
<input type="button" onclick="setIframe()" value="单击载入第二个页面" />
<iframe align="center" frameborder="0" marginheight="0" marginwidth="0" name="relnews"
                id="newframe" scrolling="no" style="width: 100%; height: 100%;display:none">
</iframe>
</p>
</body>
</html>
 

第二个文件frame2.html
 

复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>第二个要载入的页面</title>
<script type="text/javascript">
function setIframe()
{
   var f=document.getElementById("newframe");
   f.style.display="inline";
   f.src="http://www.jb200.com";
}
</script>
</head>
<body>
这是第二个页面。下面的载入是网址,是模仿了跳转功能,这样跳转不会被拦截。
<p>
<p>
<input type="button" onclick="setIframe()" value="单击载入第三个页面" />
<iframe align="center" frameborder="0" marginheight="0" marginwidth="0" name="relnews" id="newframe" scrolling="no" style="width: 100%; height: 100%;display:none">
</iframe>
</p>
<iframe align="center" frameborder="0" marginheight="0" marginwidth="0" id="newframe" scrolling="no" style="width: 100%; height: 100%;display:none">
</iframe>
</p>
</body>
</html>

您可能感兴趣的文章: