如何强制仅在IFrame中加载页面? [英] How to Force the page to be loaded only within an IFrame?

查看:163
本文介绍了如何强制仅在IFrame中加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组asp.net页面,希望它们仅在从IFrame加载时才可以访问或加载.如果试图通过浏览器地址栏直接访问页面,则该页面根本不会显示或向用户显示消息.

I have a set of asp.net pages which I wish they should only be accessible or loaded when they are loaded from an IFrame. If an attempt is made to access the pages directly via browser address bar then the page should not be displayed at all or display the message to the user.

我尝试使用Cookie和会话,但是它们并不是那么有效,因为一旦创建了cookie/会话,您就可以绕过IFrame直接从浏览器访问页面.

I tried using cookies and sesions, but they are not that effective becuase once the cookie/session is created you can access the pages directly from browser, bypassing IFrame.

我的开发平台是asp.net 2.0 +,vs2008,C#2.0 +

My development platform is asp.net 2.0+, vs2008, C# 2.0+

推荐答案

这是将脚本放在head标记中的几次更好的例子之一.

This is an example of one of the few times it is better to put the script in the head tag.

<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>

这篇关于如何强制仅在IFrame中加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆