我有两个网站..(MVC 应用程序)
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)时,如何使网站 A 显示两个选项卡以及当他们访问网站 A 时如何显示“仅一个选项卡”(主页选项卡)通过 websiteB 中的 Iframe 访问网站。 Iframe 内的网站 A 应仅显示“主页”选项卡。感谢您的想法/帮助。
最佳答案
从 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>
关于c# - 通过 url 性质控制内容的显示 - MVC/HTML/ASP/JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11904009/