次のような状況があります: url のページがありますsite.com#hash
。ブラウザ (Chrome 29 Mac、Safari、IE9 ウィンドウ) で更新ボタンをクリックすると、視覚的に更新されます (スクリプト、フォームは初期状態に戻ります) がonload
、次の JS を使用している間はイベントをトリガーしません:
window.onload = function(event){
alert('foo');
}
it works fine with refresh without hash. I understand, that browsers won't normally make a new request when the hash is altered, but it's not the case. I hit the refresh button and I see that the page actually refreshes... without firing the event, however.
I've managed to get my code work with some special functions like onReady() (included in lots of libraries)... but I'd really like to know if it's a normal behavior or a bug.
P.S. no fiddle provided, as it won't demonstrate the problem, sorry. In order to prove it, please, use this simple page with some hash like site.com/page.htm#somehash
<!DOCTYPE html>
<html>
<head></head>
<body>
123
<script>
window.onload = function(event){
alert("Hello!");
}
</script>
</body>
</html>