Reputation: 1762
I have this start page that runs on my home server, and the start page is my homepage, the page that shows up when I make a new tab etc. and it has a list of all my web apps and bookmarks.
I'd like it so when the page loads, If I want to do a google search then I can just start typing and this overlay pops up with a search bar for me to search google with.
I have seen how people would use the onkeypressed()
function to run code when something is typed in a input field but I want to run this piece of code (which will be the code that shows the overlay with the search bar) if the user starts typing anywhere on the page (when the user isn't in a input field)
e.g. The page loads and straight away the user starts typing, I want to instantly show an overlay with a search box and allow the user to type in that search box.
Can this be done, and if so, how? Is there a function for it?
Upvotes: 0
Views: 1535
Reputation: 86
Hope this help you!
<html>
<body>
<p id="demo"></p>
<script>
document.addEventListener("keypress", function(event){
var x = event.which || event.keyCode;
document.getElementById("demo").innerHTML = "The Unicode value is: " + x;
});
</script>
</body>
</html>
Upvotes: 2