我有一组 asp.net 页面,我希望它们只能在从 IFrame 加载时才能访问或加载。如果尝试通过浏览器地址栏直接访问页面,则根本不应显示该页面或向用户显示消息。
我尝试使用 cookie 和 session ,但它们并不是那么有效,因为一旦创建了 cookie/ session ,您就可以绕过 IFrame 直接从浏览器访问页面。
我的开发平台是asp.net 2.0+、vs2008、C#2.0+
最佳答案
这是少数几个最好将脚本放在 head 标记中的例子之一。
<html>
<head>
<title>sandBox</title>
<script type="text/javascript">
if (frameElement == null) {
//change location or close
window.location = "http://stackoverflow.com";
// or window.close();
}
</script>
</head>
<body>
content goes here
</body>
</html>
关于http - 如何强制页面仅在 IFrame 中加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1097117/