目的
「現在のページと同じリンク先」を判定しその際にアラートさせたいです。
現状
次のコードでは目的が実現できませんでした。原因と対策を教えて頂けませんでしょうか。
html
1<a href="http://example.com">link1</a> 2<a href="http://example.com/page/2">link2</a> 3<a href="http://example.com/apple">link3</a> 4 5<script> 6$(document).on("click","a", function(){ 7 var currentUrl = location.href; 8 var targetUrl = $(this).attr('href'); 9 if( currentUrl == targetUrl ){ 10 alert('現在のページと同じリンク先です'); 11 } 12}); 13</script>
回答2件
あなたの回答
tips
プレビュー