【问题标题】:How to understand my webpage called from external site in iframe?如何理解我在 iframe 中从外部站点调用的网页?
【发布时间】:2014-04-22 19:10:07
【问题描述】:

我想识别我网站的任何页面是否从外部网站中的 iframe 调用

我可以更改我的 _layout.cshtml。

换句话说,我希望有两种布局,一种供用户直接访问我的网站,另一种供从其他网站访问我的网站的用户使用(其他网站使用 iframe 引用我的网站)

我的问题是如何检测这两种类型并改变我的布局?

编辑 我需要知道服务器端的 iframe 才能更改它。我不想通过 javascrip 将用户重定向到某些操作 在我的某些观点中,我需要这样的命令,但如何?

@{ 
if(ViewBag.Iframe == true)
{
 layout ="_Iframelayout.cshtml"
}
else
{
 layout ="_Normallayout.cshtml"
}

}

【问题讨论】:

    标签: javascript asp.net asp.net-mvc iframe


    【解决方案1】:

    看看这个link。此链接将帮助您确定您的网站是否在 iframe 中打开。

    一旦您确定了这一点,您就可以将用户重定向到特定的控制器操作并以编程方式更改您的布局。

    【讨论】:

      【解决方案2】:

      你可以使用下面的代码这就是例子..

      <style>
        html { display :none; }
      </style>
      <script>
      if(self==top){
        window.location = "http://www.mysite.com/my_layout.cs.html";
      }else{
        window.location = "http://www.mysite.com/my_layout.cs.html";
      }
      </script>
      

      您根据 self==top 决定将页面重定向到特定类型的布局

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-07
        • 2011-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多