How does js set div not to be displayed in an iframe frame

  • 2020-03-30 00:44:28
  • OfStack

<html xmlns="" > 
<head runat="server"> 
<title> test </title> 
<script language="javascript" type="text/javascript"> 

function getStyle() { 

if ( == window.self) { 

document.getElementById("top").style.display = 'block'; 

} else { 

document.getElementById("top").style.display = 'none'; 



<body onload="getStyle();"> 
<form id="form1" runat="server"> 
<div id="top"> 
 Does not show in the framework, normal access display  

Div top is displayed when the current page is accessed normally

The page does not display div top when the current page is in the iframe

Related articles: