javascript - 如何在 iframe 中打开页面时隐藏按钮?

标签 javascript jquery html iframe

当我的 html 页面在 iframe 中打开时,我想要display: none ,即save 按钮。

我该怎么做?

这个链接可能对我有帮助,但我不明白这个link

iframe代码

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

最佳答案

使用这个:

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

最后:

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

这样,每次 test.html 位于(您的或其他人的)iframe 中时,保存按钮就会隐藏。

关于javascript - 如何在 iframe 中打开页面时隐藏按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717928/

相关文章:

html - 成为网页设计师 : CMS, 或手工

HTML 片段链接与 CSS 定位一起使用?

javascript - FormData.get 函数未定义

javascript - 模态内的 highcharts web 图表

javascript - Ajax + Django : Ajax is not recognized

javascript - 如何强制 ag-grid 滚动到选定/突出显示的行位置

html - 在本地主机服务器上找不到 png 文件

javascript - 谷歌图表,更改趋势线方程参数标签

javascript - Chart.js 中分组条形图每组不同级别

javascript - 阻止执行innerHTML