Copy the code code as follows:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
*{font-size:12px;font-family:Verdana, Geneva, sans-serif;line-height:14px}
a{color:#039}
a:hover{color:#f60}
.pop{position:absolute;left:40%;top:40%;width:300px;height:100px;background:#eee;border:1px solid #ccc}
.pop_head{position:relative;height:20px;background:#ccc}
.pop_head a{position:absolute;right:8px;line-height:20px;color:#000;text-decoration:none}
.pop_head a:hover{color:#f60;text-decoration:none}
.pop_body{padding:8px}
-->
</style>
</head>
<body>
<!--First set a layer:-->
<div id="pop" style="display:none" onclick="show(event,'pop');">
<div><a href="javascript:void(0);" onclick="hide('pop')">Close</a></div>
<div>Thank you for visiting...</div>
</div>
<!--Button of the popup layer:-->
<a href="javascript:void(0);" onclick="show( event ,'pop');"> Pop button</a>
<script type="text/javascript">
var url = '#';
function show(evt,o){
evt.stopPropagation?evt.stopPropagation():evt.cancelBubble=true;
var o = document.getElementById(o);
o.style.display = "";
}
function hide(o){
var o = document.getElementById(o);
o.style.display = "none";
window.location = url;
}
document.onclick=function(){hide('pop');}
</script>
</body>
</html>
Summarize:
1. When calling the pop-up method, pass in an event object: event.
2. Add event binding code to the pop-up method.
3. There needs to be a global js code that is used to call the method of hiding the pop-up layer when clicking on other parts.