【发布时间】:2011-10-01 19:47:37
【问题描述】:
我需要了解页面是否在 iframe 中被调用,或者是否在代码后面。这可能吗?
我需要在后面的母版页代码中确定它。
asp.net 4.0,C#
【问题讨论】:
标签: c# asp.net iframe code-behind detect
我需要了解页面是否在 iframe 中被调用,或者是否在代码后面。这可能吗?
我需要在后面的母版页代码中确定它。
asp.net 4.0,C#
【问题讨论】:
标签: c# asp.net iframe code-behind detect
一般来说不会。
当然,您可以发出检测 iframe 并重新加载页面的客户端脚本,例如一个查询字符串。
【讨论】:
这是不可能的。但是有一个解决方法。如果该查询字符串包含值,您可以使用查询字符串并检查页面加载,例如:
<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
}
}
}
【讨论】: