Prevent iframe stealing

前端 未结 6 1675
陌清茗
陌清茗 2020-12-05 20:37

I think someone is stealing my content using an iframe. My website is a forum and a user has just reported them to me.

How can I find their website programmatically

6条回答
  •  再見小時候
    2020-12-05 21:13

    With JavaScript you can do

    if(window.top==window){
     //not inside iframe
    } else {
        if(parent.parent.someFunction){
           parent.parent.someFunction();
        } else {
           alert("framing is not allowed")
        }
    }
    

    OR

    if (window.top !== window.self) window.top.location.replace(window.self.location.href);
    

    Some modern browsers also support the X-FRAME-OPTIONS header, that can have two values:

    * DENY – prevents the page from being rendered if it is contained in a frame
    * SAMEORIGIN – same as above, unless the page belongs to the same domain as the top-level frameset holder.
    

    Browsers that support the header:

    * IE8 and IE9
    * Opera 10.50
    * Safari 4
    * Chrome 4.1.249.1042
    * Firefox with NoScript
    

提交回复
热议问题