JSで奇妙な動作に気づきました
window.location.hash = '';
var hash = window.location.hash;
alert(hash + ' = ' + hash.length);
//outputs: ' = 0'
window.location.hash = '#';
hash = window.location.hash;
alert(hash + ' = ' + hash.length);
//outputs: ' = 0'
window.location.hash = '_';
hash = window.location.hash;
alert(hash + ' = ' + hash.length);
//outputs: '_ = 2'
基本的に3つの条件をトリガーしたい
- ハッシュなし
- ただハッシュ
- テキスト付きのハッシュ
ただし、JSはexample.com/とexample.com/#の違いを認識していないようです。また、ハッシュを完全に削除する方法がわかりません。
何か助けはありますか?