私はページ上にボタンを持っています。クリックすると別のページにリンクし、ローカルに保存された変数を "true"に設定します。新しいページには、setInterval関数で隠されているdivがあります。変数が "true"に設定されている場合、setIntervalが起動しないようにしたいと思います。ローカルに保存された変数をclearIntervalに使用
HTML:
<!--Page 1-->
<a href="page2.html">
<div id="view" class="mainButton">view progress</div>
</a>
<!--Page 2-->
<div id="showChart">
<p>view progress</p>
</div>
<div id="containChart">
<!--Chart-->
<canvas id="theChart" width="400" height="400"></canvas>
<!--Back to Profile-->
<div id="closeChart">close</div>
</div>
のJavaScript(いくつかのjQueryの):
displayChart();
var timeIt;
function displayChart() // Hides chart shortly after loading of page.
{
var timeIt = setTimeout(function()
{
document.getElementById("containChart").style.display = "none";
}, 0.1);
var condition = localStorage.quickAccess;
if(condition === true)
{
clearTimeout(timeIt);
}
}
// Keep chart displayed if clicked.
$("#view").click(function()
{
localStorage.quickAccess = true;
});
// Show Progress Chart.
$("#showChart").click(function()
{
$("#containChart").css("display", "block");
console.log(localStorage.quickAccess); // Logs correctly: if "#view" was clicked returns "true".
});
// Hide Progress Chart.
$("#closeChart").click(function()
{
$("#containChart").css("display", "none");
});
あなたは正しいです!私はその細部を完全に忘れてしまった。ありがとうございました! – Brian