How to type something then it should redirect us to another page in HTML and JavaScript



I made this tutorial to answer a question asked to me about how to make something that if we type a word than it redirects us to some page.

So I do this in HTML and JavaScript, and I hope I did not get it wrong. Basically when we type a word in an input field, we check the typed word, is it a specific word that we want it to redirect us to some page or not… If it is the word, then JavaScript can redirect us by location.href = “some page or url…” That’s all.

PS: Sorry I don’t know why my microphone volume is so low.

Here is the code:

<!DOCTYPE html>
<html>
	<head>
		<title>
		</title>
	</head>
	<body>
		<input placeholder="Type something" onkeyup="checkTheWord()" id="aword">
		<script>
		
			function checkTheWord(){
				var aword = document.getElementById("aword").value;
				if(aword == "google")
					location.href = "https://google.com";
				else if(aword == "youtube")
					location.href = "https://youtube.com";
			}
		
		</script>
	</body>
</html>
loading...

Leave a Reply

Your email address will not be published. Required fields are marked *