2009-07-08 56 views
2

我有一套asp.net頁面,我希望他們應該只能從IFrame加載時訪問或加載。如果嘗試通過瀏覽器地址欄直接訪問頁面,則不應該顯示該頁面或將消息顯示給用戶。如何強制只在IFrame中加載頁面?

我嘗試過使用cookie和sesions,但是一旦創建了cookie/session,它們就沒有那麼有效,您可以直接從瀏覽器訪問這些頁面,繞過IFrame。

我的開發平臺是asp.net 2.0 +,VS2008,C#2.0+

回答

5

這是幾次最好是把腳本頭標記的一個示例。

<html> 
<head> 
    <title>sandBox</title> 
    <script type="text/javascript"> 
     if (frameElement == null) { 
      //change location or close 
      window.location = "http://stackoverflow.com"; 
      // or window.close(); 
     } 
    </script> 
</head> 
<body> 
content goes here 
</body> 
</html> 
+0

非常感謝,非常有幫助。 – JoeW 2012-02-19 20:58:51

0

試試這個你標籤中:

<script> 
if(window.self !== window.top); //inside an iframe 
else window.location = "http://stackoverflow.com/" // Outside 
</script> 
相關問題