当我的 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/