巧妙使用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";
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章