http - 如何强制页面仅在 IFrame 中加载?

标签 http iframe webpage

我有一组 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/

相关文章:

javascript - Firefox 中的 `ImportNode` 并从 `iframe` 中提取元素

javascript - 获取 iframe 内容的宽高

javascript - 如何将我的网页翻译成其他语言?

internet-explorer - Google Apps for Web Apps登录无法与Internet Explorer一起使用

python - 如何更改 HTTP 响应中的链接 url?

java - android HTTP post php脚本问题

http - 每个服务器的并发HTTP/1.1连接的默认值的官方引用?

html - WatchKit 是否支持 html?有像 UIWebview 这样的 Controller 吗?

dynamic - wget应用到 "Save As Complete Web Page"

http - 在全局范围内响应 polymer 中的 401