Skip to content

Instantly share code, notes, and snippets.

@n8io
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8io/5021e93d269c85e2d193 to your computer and use it in GitHub Desktop.
Save n8io/5021e93d269c85e2d193 to your computer and use it in GitHub Desktop.
Provides a way to hide elements before the page is visible if in an iFrame.
<html>
<head>
</head>
<body>
<!-- The first element in the body -->
<script>
function inIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
if(inIframe()){
document.getElementsByTagName('body')[0].style.display = 'none';
}
</script>
...
<!-- The last element in the body. -->
<script>
(function(){
if(inIframe()){
var removeElements = ['topBorder', 'lightLine', 'header', 'navbar container', 'master-footer'];
for(var i = 0; i < removeElements.length; i++){
var foundElements = document.getElementsByClassName(removeElements[i]);
for(var j = 0; j < foundElements.length; j++){
foundElements[j].style.display = 'none';
}
}
document.getElementsByTagName('body')[0].style.display = 'block';
}
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment