2010-04-28 38 views

回答

2

我真誠地懷疑你可以從背後的代碼做到這一點。你可以在JavaScript中做到這一點,但不能從後面的代碼中做到。

如果你真的需要從後面的代碼中知道,你可能會提供一個查詢字符串參數,當你加載頁面的iframe?喜歡的東西...

<iframe src ="page.aspx?iframe=true" width="100%" height="300"> 
</iframe> 

然後在後面的代碼,你可以做這樣的事情......

// sometimes my Asp.NET, Java and PHP get a little confused 
// so maybe this might throw some no such index type errors, 
// but I think it communicates the idea 
string iframe = Request.QueryString["iframe"]; 
if(!string.IsNullOrEmpty(iframe) && iframe.Equals("true")) { 
    // this page is in the iframe 
} 
0

你應該用JavaScript來做到這一點。

2

在服務器端,您無法在客戶端檢測到此java腳本代碼應該工作。

<script type="text/javascript"> 
    if (top == self) 
     alert('Not in an iframe'); 
    else 
     alert('In an iframe'); 
</script> 
相關問題