[英]Preventing a page to be shown outside a iframe
I have a page which work like a navigation and a iframe in this page which show the content. 我在这个页面中有一个像导航和iframe一样的页面来显示内容。
Now there are some situation when the inner page is directly shown in the browser. 现在有一些情况是内部页面直接显示在浏览器中。 eg: if somebody types the inner page's url in the browser address bar, the page is displayed in the window.
例如:如果某人在浏览器地址栏中键入内页的URL,则该页面将显示在窗口中。
I want to prevent this. 我想阻止这个。
Better still, I would like to redirect to any other page. 更好的是,我想重定向到任何其他页面。
window.parent : The window object that contains the frame.
window.parent :包含框架的窗口对象。 If the the window is the top level window then window.parent refers the window itself.
如果窗口是顶级窗口,则window.parent引用窗口本身。 (It is never null.)
(它永远不会为空。)
window.top : The top level window object, even if the current window is the top level window object.
window.top :顶级窗口对象,即使当前窗口是顶级窗口对象。
window.self : The current window object.
window.self :当前窗口对象。 (It is a synonym of window.)
(它是窗口的同义词。)
So, I'd write my check like this: 所以,我会像这样写支票:
if (window.top == window.self) {
window.location = "index.html";
}
Which would be identical to the slightly more ambiguous: 哪个与稍微更模糊的相同:
if (window.top == window) {
window.location = "index.html";
}
<script language="Javascript"><!--
if (top.location == self.location) {
top.location = "index.html" // must be viewed in main index
}
//--></script>
modified it from a situation where an an iframe decides to become the main frame. 从iframe决定成为主框架的情况修改它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.