ユーザーがサイトのルート URL にアクセスしている場合に js スクリプトを実行したいと考えています。私はこのコードを使用しています:
<script type="text/javascript">
if(location.pathname == "/") {
window.open ('#107','_self',false);
}
</script>
ただし、パス名にはクエリ文字列とロケーション ハッシュが含まれていないため、http://example.com/?foo=bar# hash もスクリプトを実行します。
現在、次のように動作します。
http://example/ Root
/?querystring Root
/#hash Root
/page Not root
私はそれが次のように動作することを望みます:
http://example/ Root
/?querystring Not root
/#hash Not root
/page Not root
助言がありますか?ありがとう。