开发者

How to prevent an iframe page from being accessed directly

Continuing with my previous question on calling iframes via jscript.. I would like to implement a security feature so that anyone who access the iframe directly is redirected to a specific page.

One of the other questions asked this but was a bit more general. The code mentioned there was:

if(window.top.location == window.location){
  window.location = "http://example.com/whatever/page/you/want/them/to/go/to.html";
}

Question: Would it suffice to tag this between the and place it on my page.htm which is the one being called v开发者_开发问答ia the iframe?


That's no "security" at all. It's just annoying. It's super-easy to circumvent (e.g. by disabling JavaScript) but it will break links from search engines.

But yes, putting that code into the page which has to be loaded in side a frame/iframe is sufficient.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜