Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Check for a Hash Character in URL</title> <script> function checkHash(){ if(window.location.hash){ alert("Fragment component exists"); } else{ alert("Fragment component doesn't exist"); } } </script> </head> <body> <a href="#hint">Hint Text</a> <p id="hint"><strong>Note:</strong> Open the output in a new blank tab and click the "Check Hash" button once before clicking the "Hint text" link and once after clicking the "Hint text" link to see how it works.</p> <button type="button" onclick="checkHash();">Check Hash</button> </body> </html>