【问题标题】:is it possible to understand at Code behind whether page is being called inside iframe or not是否可以在代码后面了解是否在 iframe 内调用页面
【发布时间】:2011-10-01 19:47:37
【问题描述】:

我需要了解页面是否在 iframe 中被调用,或者是否在代码后面。这可能吗?

我需要在后面的母版页代码中确定它。

asp.net 4.0,C#

【问题讨论】:

    标签: c# asp.net iframe code-behind detect


    【解决方案1】:

    一般来说不会。

    当然,您可以发出检测 iframe 并重新加载页面的客户端脚本,例如一个查询字符串。

    【讨论】:

      【解决方案2】:

      这是不可能的。但是有一个解决方法。如果该查询字符串包含值,您可以使用查询字符串并检查页面加载,例如:

      <iframe src="Default.aspx?iframe=true" />
      

      在您的Default.aspx.cs 文件中:

      protected void Page_Load(object sender, EventArgs e)
      {
          if(!string.IsNullOrEmpty(Request.QueryString["iframe"]))
          {
              if(Convert.ToBoolean(Request.QueryString["iframe"])
              {
                  // this page is loaded in an iframe
              }
          }
      }
      

      【讨论】:

      • 这个查询字符串参数如何设置?
      • 这是一个如何创建 iframe 的示例,而不是如何检测一个。如果 iframe 代码不是您自己的,并且您必须检测到您的页面在该 iframe 中,您将如何设置此值?
      • 好吧,问题不是 iframe 代码不是我的。问题是是否可以检查页面是否加载到 iframe 中,那里没有其他限制。
      • 我同意这个要求是模棱两可的,但我选择了另一种阅读方式。所以你的答案很好,我只是想看看那段代码:) Joe 似乎暗示可以编写一个客户端脚本进行检测......
      • 实际上问题是针对其他人而不是我生成的 iframe :)
      猜你喜欢
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多