0

I apologize for being a pretty big noob, but I am trying to a utilize window.parent !== window.top if command in order to have all pages loaded from this site within an iframe to load without the footer. I have this javascript within the parent site's header, do I need to be using postmessage for the iframe to read this script? did i do it completely incorrectly? i hope that this can help convey what I am trying to do.

$(document).ready(function() {
   var windowURL = window.location.href;
   console.log(windowURL);
   if (windowURL.indexOf('nofooter') > -1) {
     $('#container__footer').css('display', 'none');
   }
    if (window.parent !== window.top) {
     $('#container__footer').css('display', 'none');
}})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<iframe src="different website with windowURL nofooter string" height="1800" width="90%" frameborder="0" scrolling="no"></iframe>
Rob Moll
  • 3,345
  • 2
  • 9
  • 15
elle
  • 1
  • 1
  • The logic for checking the top.location.href to the location.href would be in the iframe, not on the page that the iframe resides in. – Taplar Feb 12 '20 at 23:00
  • @Taplar hey! thanks for the info. so i tried to narrow down what i needed to do to just, but I am not sure if it is not working because it is not being received as a postmessage from parent to iframe or something else. – elle Feb 12 '20 at 23:24
  • There wouldn't be a post message from parent to iframe. You're not doing any sort of post message logic here. And again, the logic for checking if you are in the top and not in an inframe, would be done **in the iframe**, not the parent. The parent's top is going to match it's own location – Taplar Feb 12 '20 at 23:29
  • ahh ok i see. that's good to know. so i get that the logic check needs to be from within the iframe, but i would need to still set up the footer css hiding code within the parent site, is that correct? – elle Feb 12 '20 at 23:41
  • Is the footer in the parent or in the iframe? – Taplar Feb 13 '20 at 16:20
  • @Taplar the footer is in the iframe from the other domain source, so i was trying to utilize the info from https://stackoverflow.com/a/41594695/12888680 but i was worried if it would persistently carry that parameter after the '?' to all pages from within the iframe. – elle Feb 13 '20 at 22:22
  • i think i just ended up solving this a much easier way by just forcing all pages on the main site's css to have the content have a min-height of my iframe's height so that the pages you can navigate to from where i start the iframe wont have the footer. it's not the best way to do it, and technically the footer is still there, but it shouldn't be an issue and it should be able to effectively do what i needed it to. not really a coding solution unfortunately, but it seems to be the only way i could really get this to feasibly work the way i wanted it to. at least with my knowledge. – elle Feb 13 '20 at 23:14

0 Answers0