Add a search box to query other external search engine

Mason Yang asked on May 24, 2019 19:50

Hi, we are planning to redesign our library website. We would like to add a search box on our library website, which can be used to send a query to an external search engine. An example of the search box can seen on George Washington University Library's website at: https://library.gwu.edu/. On this page, the search box is under the sentence "What would you like to find at the libraries today?". I tried to add a "Form" with one textbox and a submit button on our page, but I can't find a way to link an action to that form. Ideally, here is how we would like it to work: 1. User type in some words in the textbox and then click on the submit button 2. the page take the inputs from the textbox and use the input to query a search engine, in our case, https://wrlc-mar.primo.exlibrisgroup.com/discovery/search?sortby=rank&vid=01WRLC_MAR:01WRLC_MAR. Any advice will be appreciate it. thanks, Mason

Recent Answers


Brenden Kehren answered on May 24, 2019 20:09

Your searchbox code can simply be plain HTML with maybe some javascript to create that proper link to redirect to when the button is clicked. No need to use a Kentico webpart as the only processing to be done is on the 3rd party site.

Your jQuery could be something as simple as:

$('.button1').click(function() {
   window.location = "https://www.example.com/index.php?id=" + this.id;
});
1 votesVote for this answer Mark as a Correct answer

Mason Yang answered on May 24, 2019 22:33

Hi Brenden, thank you so much for your reply! I am very new to this, so please forgive me for my very newbie questions. I tried to follow your advice, but still can't get it to work. Here is what I have done so far, could you point out what I have done wrong? 1. add the following HTML code to get a textbox and a button

  1. add the following code to the HeadHTMLCode section of that page: $('.submitButton').click(function() { window.location = "https://www.cnn.com"; });

I just want to see if I can redirect that page to another after clicking on the button, but it doesn't work for me. Did I miss anything here?

Also, I want to check if there is anyway to add a "form" to a Kentico page following the example below from the search engine provider: (See the original instruction at: https://knowledge.exlibrisgroup.com/Primo/Product_Documentation/050New_Primo_User_Interface/New_UI_Customization_-_Best_Practices#Creating_a_Search_Box_With_Deep_Links_to_the_New_UI)

thank you again for your help!

Mason

0 votesVote for this answer Mark as a Correct answer

Eric Dugre answered on May 29, 2019 18:55 (last edited on May 29, 2019 18:55)

Mason,

It looks like you're having some trouble with standard HTML/JS rather than Kentico itself. The code you provided is not valid- see https://stackoverflow.com/a/506004/5656214 for examples of how to redirect users via javascript.

In regards to your second question, it looks like this approach requires using a form tag, but in webforms the entire page is already wrapped in a form tab so this won't work. Instead, you could probably implement similar functionality using AJAX, or the system you are attempting to integrate with may have some API you can use.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.