Gravatar for jschjolberg@awareweb.com

Question by jschjolberg, May 13, 2014 5:40 PM

Can you pass a keyword search term in the query string using the JavaScript Search Framework?

Can I link to my search page with a keyword in the query string and have that load results when using the JavaScript Search Framework? Like this:

http://www.mysite.com/searchpage?q=searchterm

Is there a way for the initial search to use this keyword (q) in the query string?

Thanks!

1 Reply
Gravatar for glaporte@coveo.com

Answer by Gregory Laporte, May 13, 2014 5:43 PM

Sure,

If you have history enabled on your SearchInterface, you can use the following: http://www.mysite.com/searchpage#q=searchterm.

The processing is done client side rather than server side, so you need to add the #.

Gravatar for olamothe@coveo.com

Comment by olamothe, May 14, 2014 11:00 AM

Just a small correction, the history is not on by default. You need to add this to your search interface

<div class='CoveoSearchInterface' data-enable-history='true'></div>

Gravatar for jschjolberg@awareweb.com

Comment by jschjolberg, May 14, 2014 1:38 PM

Thanks - do you know if there is a trick to getting this to work when linking from another page? This does work when I am on the page and just add "#q=searchterm" to the end but when I link to the page with this in the query string it does not. I have data-enable-history set to true.

Gravatar for glaporte@coveo.com

Comment by Gregory Laporte, May 14, 2014 1:43 PM

It's not a query string parameter. You can craft a link and put the q= after the # instead of putting it directly after the searchpage.

Gravatar for jschjolberg@awareweb.com

Comment by jschjolberg, May 14, 2014 3:26 PM

Thanks - I'll look into it.

Gravatar for apare@coveo.com

Comment by Alexandre Paré, May 15, 2014 3:33 PM

Can you give me the line where you get this error?

Gravatar for jschjolberg@awareweb.com

Comment by jschjolberg, May 22, 2014 2:16 PM

I've resolved this - it was unrelated to Coveo. Sorry for the hassle!

Ask a question