スクロール可能なDIVがあり、その中にテーブルがあります。ある種のonmove()メソッドでスクロール位置をキャプチャして、それをCookieに入れ、ページがリロードされたときにスクロールバーを同じ位置に復元できるようにすることは可能ですか。これが私のJSPコードです
<div id="wordListTableDiv" style="overflow: auto;height: 700px; width: 320px; max-width:320px; border:2px solid black; background-color: #FFFFF0; padding: 10px">
<br>
<div>
<br>
<input type="button" value="Show All" onclick="getWordList()" style="float: left;">
<input type="button" value="Hide Ignored and Good" onclick="hideIgnoredAndGoodWords();" style="float: right;">
</div>
<br></br>
<table id="wordListTable" border=1 >
<thead id="wordListTableHead"><tr>
<th width="150">Word</th>
<th width="150">State</th>
</tr></thead>
<tbody><%-- Empty to begin with, filled by JavaScript. --%></tbody>
</table>
</div>
私が持っているJavaScriptは
function setScrollPosition()
{
//If the scroll position was set previously then reposition it to the old value.
var scrollPosition = readCookie("scrollPositionCookie");
if( scrollPosition != null )
{
$("#wordListTableDiv").scrollTop( scrollPosition );
}
}
ただし、firebugを開いて、Cookieからスクロール値を設定するブレークポイントを設定しない限り、常に位置「0」になります。これはタイミングの問題だと思いますか?
質問は無視してください。タイミングの問題を引き起こしているJSON呼び出しを見つけました:(