Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if my page is being loaded in an iFrame in a Django view

How can I detect in a view function that the page is being loaded in an iFrame? I want to change the page slightly if that is the case. Is there any way to do this?

Note, Im not looking for click jacking protection. I want to make changes to my view if the page is being loaded in an iframe.

like image 744
darkhorse Avatar asked Oct 16 '25 08:10

darkhorse


1 Answers

You can check the {{ request.META.HTTP_SEC_FETCH_DEST }} variable in the template. Example:

<section id="header" class="hero is-small is-info {% if request.META.HTTP_SEC_FETCH_DEST != 'document' %}is-hidden{% endif %}">

List of possible values for HTTP_SEC_FETCH_DEST: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Dest

like image 168
Steep Pepper Avatar answered Oct 18 '25 01:10

Steep Pepper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!