I have two pages, one is index.html
another is iframe.html
How to let the iframe.html
only be loaded in开发者_JAVA技巧 index.html
?
If iframe in other pages
or directly type http://www.site.com/iframe.html
in browser, the page only show some words like opps~~something is wrong.
something like bing shopping
.
Thanks.
if( self == top )
location.href='/';
Put this in the iframe page
You could use the window.parent.location
to fetch the parent url inside the iframe and act accordingly. If window.parent is not defined it probably means that the iframe.html was called directly. If it is defined inspect the value and ensure it comes from /index.html on your domain.
I think this should do it...
var inIframe = window.location != window.parent.location;
You can use this javascript in your iframe.html:
if (top.location.href != 'http://www.site.com/index.html') {
// the proper redirect here
top.location.href = 'http://www.site.com/index.html';
}
this way it will always be loaded as an i frame
精彩评论