Javascript 如果页面嵌入在iframe中,如何显示特定的HTML元素?

Javascript 如果页面嵌入在iframe中,如何显示特定的HTML元素?,javascript,html,iframe,Javascript,Html,Iframe,如果有人使用URL的,我想在我的网站上显示一个小水印,如果没有检测到使用,我不想显示HTML部分 JavaScript部分 <script> if(window != window.top) { // if true I want to show the HTML else nothing }; </script> if(window!=window.top){ //如果为真,我想显示HTML,其他什么都不显示 }; 我想显示的HTML部分 <a href

如果有人使用URL的
,我想在我的网站上显示一个小水印,如果没有检测到
使用,我不想显示HTML部分

JavaScript部分

<script>
if(window != window.top) {
  // if true I want to show the HTML else nothing
};
</script>

if(window!=window.top){
//如果为真,我想显示HTML,其他什么都不显示
};
我想显示的HTML部分

<a href="https://example.com" style="position: fixed; bottom: 5px; text-align: center; width: 100%;" target="_blank">example.com</a>


如何隐藏或显示此HTML元素?

将HTML
display:none
设置为隐藏为默认行为,并给它一个
id=“watermark”


$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
document.getElementById('watermark').style.display='none';
});});
单击隐藏
您添加了“对不起,我是一名编码新手”,但这实际上并没有为问题添加任何说明。缺少特定的问题陈述或问题,例如“如何隐藏或显示此HTML元素?”。你可以参考那些有助于你把问题写得更清楚的东西。
<a href="https://example.com" id="watermark" style="display:none; position: fixed; bottom: 5px; text-align: center; width: 100%;" target="_blank">example.com</a>
if(window!=window.top) {
    document.getElementById('watermark').style.display = 'block';
};