Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
という名前のページがあり、index.htmlそれをロードしたいindex.html#home
index.html
index.html#home
ID が異なる要素がほとんどなく、デフォルトで #home コンテンツをロードしたいためです。
そのため、ページにヒットindex.htmlすると、リロードindex.html#homeされます (URL にハッシュが指定されていない場合を除く)。
どのように可能ですか?そして私の英語を許してください。
これを(NOT head- コメントを参照してください)HTMLページの一番下に入れます:
head
<script type='text/javascript'> document.getElementById("home").scrollIntoView(); </script>
これを試すことができます( MDNを確認してください)
if(!window.location.hash) { location.hash = '#home'; }
デモ。
あなたがしようとしているのが、ページロード時に div にスクロールすることである場合は、これを読む (/適用する) ことをお勧めします:
jQuery:ページの読み込み時に特定のアンカー/divにスクロールする方法は?