检查页面是否重新加载
我的网站有问题。所以,我有一个像这样的adsense的div:
I have a problem with my site. So, I have a div with adsense like this :
<div class="not-display" id="addsense-pub">
........................................
</div>
在2场比赛后的.js中,执行以下javascript:
In the .js after 2 games I execute the following javascript :
if(obj.number_games_adresse % 2 === 0){
document.getElementById('addsense-pub').setAttribute('class','display-block');
document.getElementById("game").style.visibility = "hidden";
}
div游戏是包含游戏的div。
The div "game" is the div which contains the game.
现在,如果我显示adsense-pub并且用户刷新页面,则该酒吧消失。不过,如果用户刷新页面,我想显示这个div。是否有这种情况下的现有解决方案?
Now if I show the adsense-pub and the user refreshes the page, the pub disappears. However I want to show this div if user refreshes the page. Is there an existing solution for this case?
我重新创建了您的场景。您可以在这种情况下使用会话来做到这一点......
I recreated your scenario. You can use sessions in this case to do this...
请参阅jsfiddle: http://jsfiddle.net/wde20oj2/
See the jsfiddle for this: http://jsfiddle.net/wde20oj2/
您可以查看会话以查看广告是否显示。
You can check the session to see if the ad was displayed. If it was go ahead and display it again.
<!DOCTYPE html>
<html>
<head>
<title>Some JavaScript Example</title>
<style>
.not-display {
display:none;
}
.display-block {
display: block;
}
</style>
</head>
<body>
<div class="not-display" id="addsense-pub">
Hello... I am an add!
</div>
<div id="game">
Hello... I am a game!
</div>
<br>
<a href="#" id="click-me">Increment Games...</a>
<br><br>
<a href="#" id="clear-me">Clear all items!!!</a>
<!-- JavaScript -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
sessionStorage.setItem('games', 0);
var data = sessionStorage.getItem('show-add');
if(data == 1)
{
$("#addsense-pub").removeClass('not-display');
$("#addsense-pub").addClass('display-block');
}
$("#click-me").click(function(){
var gamer = sessionStorage.getItem('games');
if(gamer < 1)
{
gamer += 1;
sessionStorage.setItem('games', gamer);
} else {
$("#addsense-pub").removeClass('not-display');
$("#addsense-pub").addClass('display-block');
sessionStorage.setItem('show-add', 1);
}
});
$("#clear-me").click(function(){
sessionStorage.setItem('games', 0);
sessionStorage.setItem('show-add', 0);
window.location.reload()
});
</script>
</body>
</html>