0

I want to display: none , the save button , when my html page opens in iframe.

How can I do it ?

This link might help me , but I did not understand this link.

iframe code

<HTML>  
 <BODY>
   <iframe id="myiFrame" src="file:///C:/Users/Prashant/Desktop/test.html"> </iframe>
  </BODY>
</HTML>

test.html

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <HTML>
   <BODY>
         <button id="hideInIframe" >save</button>
         <button id="getData" >get</button>
   </BODY>
 </HTML>
Community
  • 1
  • 1
unknownbits
  • 2,855
  • 10
  • 41
  • 81

2 Answers2

1

Use this:

if ( window.self !== window.top ) {
// you're in an iframe
}

Finally:

if ( window.self !== window.top ) {
  $("#hideInIframe").css('display','none');
}

This way, each time test.html is in an iframe (of yours, or of anyone else), the save button is hide.

3pic
  • 1,188
  • 8
  • 26
0

In your test.html add this script and do one change add a name attribute to the iframe object:

<iframe id="myiFrame" id="myiFrame" src="file:///C:/Users/Prashant/Desktop/test.html"> </iframe>

Then add this script.

<script>
   document.addEventListener('DOMContentLoaded', function(){
      if(window.name === 'myiFrame'){
        document.querySelector('#hideInIframe').style.display = 'none';
      }
   });
</script>
Jai
  • 74,255
  • 12
  • 74
  • 103