css - frameset的问题

查看:108
本文介绍了css - frameset的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

在点击打开3.html后 点击浏览器刷新时怎么样让它还停留在打开的3.html页面呢 不想让它刷新后回到1.html的页面 这个有办法吗?

1.html
<html>
<head>
<meta charset="UTF-8" />
</head>
<frameset>
  <frame src="2.html" />
</frameset>
</html>

2.html

<html>
<head>
<meta charset="UTF-8" />
</head>
<a href="3.html">aaa</a>
</html>

3.html
<html>
<head>
<meta charset="UTF-8" />
</head>
55555
</html>

解决方案

使用 _top 窗口,会整个页面跳转。

2.html

<html>
<head>
<meta charset="UTF-8" />
</head>
<a href="3.html" target="_top">aaa</a>
</html>

还可以通过location.hash,location.search,cookie来保存最后的页面,都可以通过修改 1.html实现,其他页面不用改动。

1.html

<html>
<head>
<meta charset="UTF-8" />
<script>
window.onload = function(){
    var iframe = window.frames['frame-page'];
    var domframe = document.getElementsByName('frame-page')[0];
    //看你保存在哪,用改用什么方式读取,这里用 location.hash
    if( location.hash != "" ){
        iframe.location.href  = location.hash.substr(2);
    };
    domframe.onload = function(){
        //将 框架 内页面的 地址保存再 1.html中
        location.hash = iframe.location.pathname;
    };
}
</script>
</head>
<frameset>
  <frame src="2.html" name="frame-page"/>
</frameset>
</html>

点击3.html后,三种方式的区别:
location.hash /1.html#/3.html
location.search /1.html?/3.html
document.cookie /1.html (不变)

如果都是用新的浏览器,都支持HTML5,还有localStorage、sessionStorage等地方可以保存,路径也是 /1.html不变。

这篇关于css - frameset的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆