首先设置一个div层 以及css
<div id="firstMask" style="display: none;"></div>
<style type="text/css">
html,body {
height: 100%;
position: relative;
}
#firstMask {
width: 100%;
height: 100%;
position: fixed;
display: none;
top: 0;
left: 0;
z-index: 9999;
cursor: pointer;
background-color: transparent;
}
</style>
js代码
<script>
$(document).ready(function() {
if(!window.name) {
//console.log("第一次打开");
window.name = "yuttname" ;
$("#firstMask").show(); // + 新增
$('#firstMask').click(function () {
$("#firstMask").hide()
if(location.href.indexOf('www.isiyuan.net') !== -1){
window.open("http://www.baidu.com");//第一次打开时设置name
}else{
window.open("http://www.baidu.com");//第一次打开时设置name
}
localStorage.clear(); //清全部缓存
});
} else { // 不是第一次打开 将 遮罩去掉
$("#firstMask").hide()
}
});
</script>