Skip to content

Commit

Permalink
Improved iframe handling: headers and footers are hidden when '?for_i…
Browse files Browse the repository at this point in the history
…frame=true' is in the link parameters
  • Loading branch information
Michael Greenburg committed Feb 7, 2024
1 parent 3160411 commit 9c06c64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bundle exec jekyll serve

## Enhancements

Adding `?linktarget=top` to the URL for a page on this site will add `target="_top"` to each link on said page, allowing it to be used in a iframe with less wonkiness. This should allow smoother integration with Canvas once I get around to it.
Adding `?for_iframe=true` to the URL for a page on this site will add `target="_top"` to each link on said page and hide the header and footer, allowing it to be used in a iframe with less wonkiness. This should allow smoother integration with Canvas once I get around to it.

"Shell and Slurm Practice" is meh; it'd be nice to have a `find` thrown in there (plus material on `find`), and make it more open-ended and amenable to combining sed/grep/awk.

Expand Down
10 changes: 9 additions & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
{%- if jekyll.environment == 'production' and site.google_analytics -%}
{%- include google-analytics.html -%}
{%- endif -%}

<!--use MathJax to render formulas-->
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<!--hide header and footer when the page is displayed in an iframe-->
<style>
body.hide-header-and-footer header {display: none; }
body.hide-header-and-footer footer {display: none; }
</style>
<!--JavaScript for iframe handling-->
<script src="/sci-comp-course/assets/make-iframes-work.js"></script>
</head>
</head>
9 changes: 6 additions & 3 deletions assets/make-iframes-work.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Adds `target="_top" to every link on the page so that the page can be used by iframes if 'linktarget=top' is in the link parameters; for use with Canvas

document.addEventListener('DOMContentLoaded', function () {
var UrlParams = new URLSearchParams(window.location.search);
if (UrlParams.get('linktarget') === 'top') {
const UrlParams = new URLSearchParams(window.location.search);
if (UrlParams.get('for_iframe') === 'true') {
// Add target="_top" to links
var links = document.getElementsByTagName('a');
for(var i=0; i<links.length; i++) {
if (!links[i].hasAttribute('target')) {
links[i].target = '_top';
}
}
// Hide header and footer
document.body.classList.add('hide-header-and-footer')
}
});
});

0 comments on commit 9c06c64

Please sign in to comment.