1

I have read the question here regarding the general case, but I am interested in how to do this in Django. I am assuming it will be a combination of code in view and template.

Excessive details:

More specifically I do not want to include top menu and footer if the page is loaded in iframe (using lightbox). For now I check the flag in template:

{% block header %}
    {% if not lightbox %}{{ block.super }}{% endif %}
{% endblock header %} 

which I have set in the view based on the url where the page is opened from:

if http_referer and http_referer.__contains__("/specific/page/"):
    context["lightbox"] = True

This is obviously not flexible. For example I have a link to contact details in the footer shown on every page. If a user clicks on it, an iframe is opened with lightbox (here I do not want to see the footer and top menu in iframe again). But if the user opens the link in a new tab, I want there to be the footer and top menu for easier navigation and style consistency. Notice that in both case the user is opening the link from the same page. Thus the above solution does not work.

Edit:

@dotcomly The question you suggested as duplicate is very similar but not helpful in my case as I strictly want to use the same url (like described above) and change the content depending on context (if the content is loaded in iframe or main window). The (accepted) answer to the other question suggests using different urls which is not acceptable in my case.

Community
  • 1
  • 1
dsalaj
  • 2,857
  • 4
  • 34
  • 43
  • Possible duplicate of [django - change content inside an iframe](http://stackoverflow.com/questions/2406408/django-change-content-inside-an-iframe) – dotcomly Oct 28 '15 at 04:15

1 Answers1

0

Temporarily I solved my problem by adding the following script to the template of the pages that may be loaded in the iframe:

<script type="text/javascript">
    function inIframe () {
        try {
            return window.self !== window.top;
        } catch (e) {
            return true;
        }
    }
    if(inIframe()) {
        $('header').css('display', 'none');
        $('footer').css('display', 'none');
        // or anything else you may want to do
    }
</script>
dsalaj
  • 2,857
  • 4
  • 34
  • 43