<分区>
我有一个 ASPX 页面,有时会加载到我的应用程序中的 iFrame 中,有时不会。从背后的代码中,您如何检测您的页面是否是从 iFrame 加载的。
<分区>
我有一个 ASPX 页面,有时会加载到我的应用程序中的 iFrame 中,有时不会。从背后的代码中,您如何检测您的页面是否是从 iFrame 加载的。
最佳答案
我真的怀疑你能否从后面的代码中做到这一点。您可能可以在 JavaScript 中执行此操作,但不能从后面的代码中执行。
如果你真的需要从后面的代码中知道,你可能会在 iframe 中加载页面时提供一个查询字符串参数?像...
<iframe src ="page.aspx?iframe=true" width="100%" height="300">
</iframe>
然后在后面的代码中你可以做类似...
// sometimes my Asp.NET, Java and PHP get a little confused
// so maybe this might throw some no such index type errors,
// but I think it communicates the idea
string iframe = Request.QueryString["iframe"];
if(!string.IsNullOrEmpty(iframe) && iframe.Equals("true")) {
// this page is in the iframe
}
关于c# - 如何判断您的页面是否在 .Net 中的 iFrame 中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2730516/