Wikipedia Viewer - Would like you to critique it

Hey! Below is the link of my Wikipedia Viewer -


Open it, test it and let me know what do you think about it…

Works well :thumbsup:

Try triggering a search when Enter is pressed

Would you like to guide me on that?

You can add a “keypress” event handler to Window - this will capture all key presses in the Tab.
Inside the handler you can check the Event’s “key” property and if it matches “Enter”, you can call your search method, or your search-button event handler from there.

A good practice is to use Event.preventDefault() for your matched key(s). If you miss this, you can have some weird behaviour from the browser keybinds, e.g. page reloads from form elements and other funny stuff.

Or if you’re using jQuery, you can use

$("#userInput").on("keypress", function(event) {
  // things that will happen when a key is pressed
  // while the focus is on the text box
});

However you’ll only want things to happen when Enter is pressed. The event object contains the char code of the pressed key in event.which. You’ll have to check if the char code of the pressed key is the char code for Enter.

2 Likes

Thanks dude for your time! Appreciate it! Will definitely try to add this functionality according to your method.

Done! Have a look now and tell me about it!

Enter key works. Nice! :thumbsup:

1 Like

The design looks good! However, some search strings produce unsightly snippets. For example, if you search the string “That”, the first two results have ugly snippets.

I have this issue as well and am looking into it so, unfortunately, I cannot help (yet).

The sample app does not have this problem.

EDIT: Try using Opensearch. You will have to change your API call, but it looks like it is working for me.

EDIT 2: I found the Opensearch returned the reults out of order compared to the sample app. I used a generator instead. The tricky part was to return the extra. This page was useful. Make sure the right values are being used for the parameters.