[英]How do I toggle 1 boolean in javascript every time the page loads, without localstorage or cookies?
I need to toggle a boolean every time the page loads. 每次页面加载时,我需要切换一个布尔值。 I can't use localStorage OR cookies.
我不能使用localStorage或cookie。
I've tried using localStorage and cookies. 我试过使用localStorage和cookie。 problem is that i'm in a sandbox that doesn't allow that.
问题是我在不允许的沙箱中。
What I CAN do is do requests to webpages. 我能做的是向网页提出请求。 Maybe one can toggle between returning true or false every time a website loads;
也许可以在每次加载网站时在返回true或false之间切换。 like:
喜欢:
First load: 第一次加载:
HTTP GET returns true (or 1, it's just an example) HTTP GET返回true(或1,这只是一个示例)
Second load: 二次负荷:
HTTP GET returns false (or 0) HTTP GET返回false(或0)
Third load: 第三次加载:
HTTP GET returns true (or 1) HTTP GET返回true(或1)
ETC. 等等。
Is there an existing API or something for that? 是否有现有的API或其他东西?
You can use hash, something like: 您可以使用哈希,例如:
<span id="result"></span>
<script>
if (window.location.hash == '#1') {
document.getElementById('result').innerHTML ='0';
window.location.hash = '0';
} else {
document.getElementById('result').innerHTML ='1';
window.location.hash = '1';
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.