2012-08-10 52 views
0

我有兩個網站。(MVC應用程序)控制顯示器 - MVC/HTML/ASP/JS

www.WebsiteA.com(中有兩個選項卡)這樣的..在它的「.master」頁面。

<ul id="module" class="module">  

     <li id="home"><%=Html.ActionLink("Home", "ActionHome", "Home")%></li> 
     <li id="Pay"><%=Html.ActionLink("Payment", "ActionPay", "Payment")%></li> 

    </ul> 

如果有一個人去的網站直接www.websiteA.com,這是他們應該看到的,兩個標籤,首頁和付款。

還有另一個網站可以說www.WebsiteB.com在其中的一個頁面上有此iframe。 iframe的基本指向第一個網站A.

這是B網站www.websiteB.com/linktoWebsiteA

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

    <iframe src="http://www.websiteA.com"</iframe> 

</asp:Content> 

我的問題是:如何讓我的網站表演兩個選項卡時,一些人去直接到網址(www.websiteA.com),當他們通過網站B中的Iframe訪問網站時,我如何顯示「只有一個標籤」(主頁標籤)。 Iframe內的網站A只能顯示Home標籤。感謝您的想法/幫助。

回答

3

來自iframe的呼叫時,您可以通過查詢字符串參數:

<iframe src="http://www.websiteA.com/?iframe=true"</iframe> 

,然後使用iframe查詢字符串參數,以顯示你想要的標籤:

<ul id="module" class="module">  
    <li id="home"><%=Html.ActionLink("Home", "ActionHome", "Home")%></li> 
    <% if (!string.IsNullOrEmpty(Request["iframe"])) { %>  
     <li id="Pay"><%=Html.ActionLink("Payment", "ActionPay", "Payment")%></li> 
    <% } %> 
</ul> 

另一種可能性是使用javascript是因爲如果您不想傳遞某些附加指示(例如查詢字符串參數),這是瞭解網站是否在iframe內運行的唯一方法。

<script type="text/javascript"> 
    if (top !== self) { 
     // running inside an iframe => hide the tabs you don't want 
    } 
</script> 
+0

謝謝。很棒。 – ZVenue 2012-08-10 15:21:47