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>

2 Answers 2

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.

0
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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.