「window.location.hash」を新しく学び、「window.location.href 」の代わりにjqueryコードで試してみましたが、どちらも同じ結果になりました。
コードはここにあります:
window.location.href = ($(e.currentTarget).attr("href"));
window.location.hash = ($(e.currentTarget).attr("href"));
それらの違いは何ですか?
「window.location.hash」を新しく学び、「window.location.href 」の代わりにjqueryコードで試してみましたが、どちらも同じ結果になりました。
コードはここにあります:
window.location.href = ($(e.currentTarget).attr("href"));
window.location.hash = ($(e.currentTarget).attr("href"));
それらの違いは何ですか?
のような URL の場合http://[www.example.com]:80/search?q=devmo#test
hashは、# 記号を含む、# 記号に続く URL の部分を返します。hashchange イベントをリッスンして、サポートしているブラウザーでのハッシュへの変更の通知を受け取ることができます。
Returns: #test
hrefは URL 全体を返します。
Returns: http://[www.example.com]:80/search?q=devmo#test
たとえば、それをテストしますhttp://stackoverflow.com/#Page
href = http://stackoverflow.com/#Page
hash = #Page
hash
とhref
はどちらもwindow.location
オブジェクトのプロパティです。hash
は URL の一部#
(または がない場合は空の文字列#
) であり、href
は URL 全体の文字列表現です。
hash プロパティは、ハッシュ記号 (#) を含む URL のアンカー部分を返します。