c# - 通过 url 性质控制内容的显示 - MVC/HTML/ASP/JS

标签 c# javascript asp.net html asp.net-mvc

我有两个网站..(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/

相关文章:

c# - 以编程方式设置 Application Insights 检测键会引发错误

c# - 在多个页面上打印包含列表框的堆栈面板 wpf

JavaScript 函数变量

javascript - 如何使用 thymeleaf 通过参数传递隐藏字段?

asp.net - Azure 网站 301 重定向 - 我将其放在哪里?

c# - 如何在延迟后重定向到另一个页面

c# - DotNetZip - 无法访问已关闭的流

c# - .NET 有 'Mandatory Parameter' 这样的东西吗?

javascript - Node js Array.push() 无法使用 mongoose 工作

c# - 在 C# 中以编程方式将文本添加到剪贴板