`
ruruhuang
  • 浏览: 190197 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

巧妙使用javascript让你的页面程序处于index frame中。

阅读更多
假如我们有这个一个页面,  index.html
<frameset framespacing="0" border="false" cols="180,*" frameborder="1">
<frame name="left"  ="" scrolling="auto" marginwidth="0" marginheight="0" src="Toc.html">
<frame name="main" scrolling="auto" src="Content.html">
  </frameset>
  <noframes>
  <body>
 

This page uses frames, but your browser doesn&apost support them.


  </body>
  </noframes>

Toc.html是目录页面, Content.html是内容页面。     

场景1:假如一个用户登入后, 进入index.html,然后用户过了很长一段时间没有操作session timeout了。这时候用户再去点页面的操作的话,这时候Content.html会转到登入页面, 但是因为在一个frame里面, 所以登入页面会在index.html中。我们希望他不出现在index.html中, 清在登入页面加上下面这段javascript
<script type="text/javascript">
    if (window.top != self){
        window.top.location = self.location;
    }
</script>

场景2:我们希望右边的内容页面不能独立的出现(即一定要出现在index.html中),我们也需要在每个在“main” frame的页面加上下面这段javascript
if (window.top == self){
    // ensure sub page would contain in index page
    window.location="index.html";
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics