JavaScriptHard
How can you prevent clickjacking attacks?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
To prevent clickjacking attacks, you can use the X-Frame-Options HTTP header to control whether your site can be embedded in iframes. Set it to DENY to prevent all framing, or SAMEORIGIN to allow framing only from the same origin. Additionally, you can use the Content-Security-Policy (CSP) header with the frame-ancestors directive to specify which origins are allowed to frame your content.
http
X-Frame-Options: DENY
http
Content-Security-Policy: frame-ancestors 'self'
