Gravatar for ahmedokour86@gmail.com

Question by aokour, Sep 2, 2015 5:01 PM

"beforeRedirect" is not firing

Hi, We are trying to check if the user search for a specific keywords, then redirect to a specific product page directly, else the user gets redirected to the search page, I tried using "beforeRedirect" event, for some reason the event does not get triggered.

Here the code i wrote for my standalone searchbox:

    searchInterface = Coveo.$('#searchBox');
    searchInterface.coveo('initSearchBox', '/MySearchPage');

     searchInterface.on('beforeRedirect', function (e, data) {
           alert('I got to here');
      });

Is there anything wrong i'm doing here?

Sitecore: 7 CFS: August Release 2015

Thanks

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Sep 2, 2015 5:29 PM

The "beforeRedirect" event is available since the June 2015 release (product version: 0.9.1530, JavaScript library version: 0.9.1287.24) of the Coveo JavaScript Search Framework. The August 2015 release of Coveo for Sitecore packages an older version of the JavaScript library (version 0.9.1146). That's why it doesn't work.

The September 2015 release of Coveo for Sitecore, that will be available on September 3rd 2015, will package the JavaScript library version 0.9.1287.53. Your code will then work as expected if you upgrade to that release.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Sep 2, 2015 5:30 PM

You can see the JavaScript library version you are using by executing this JavaScript operation in your browser console:

Coveo.version;

It will return an object. You need to look at the lib property:

Object {lib: "0.9.1146.26", product: "0.0.0.0", supportedApiVersion: 2}
Gravatar for ahmedokour86@gmail.com

Comment by aokour, Sep 3, 2015 2:48 AM

Thanks, Is there a way to implement what i'm trying to do here without using "beforeRedirect"?

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Sep 3, 2015 9:41 AM

Another approach that would improve the user experience is page/result suggestion in the search box like we have on https://developers.coveo.com and https://search.coveo.com

It can be implemented with the OmniBoxResultList component (see OmniBoxResultList Component) of the Coveo JavaScript Search Framework.

This is a good user experience because the user choose himself to open a document instead of executing a search.

Ask a question