Preventing Third-Party iframe Embedding
Website owners often face the issue of their pages being embedded within frames (iframes) on third-party websites. While the referrer request header proves ineffective in detecting this scenario during page loading, there are several approaches to address this problem.
JavaScript Detection
After the page loads, JavaScript can be employed to detect if it is being displayed within a frame. By comparing the top and self properties, one can determine if the page is embedded. If they differ, the page is within an iframe.
X-FRAME-OPTIONS Header
Some modern browsers support the X-FRAME-OPTIONS header, which offers two options:
Browsers such as Picasa respect this header and prevent embedding from third-party websites.
Browser Support for X-FRAME-OPTIONS Header
Browsers that support X-FRAME-OPTIONS with their minimum versions include:
The above is the detailed content of How Can Website Owners Prevent Third-Party Iframe Embedding?. For more information, please follow other related articles on the PHP Chinese website!