Google Product Forums

Re: Open results in same window?

omr May 8, 2012 6:34 PM
Posted in group: Google Custom Search

Categories: Implementation :


As a further suggestion:
Since you plan to use the 'two page' layout -- in which a submitted query will be passed (via URL parameters) to your results page -- perhaps you may also want to consider enabling history management.

History management can be helpful when using the browser back-button or other means to navigate back to previously displayed search-results pages and states.  (Quoting from the documentation linked below:  "History management uses the web browser URL hash to store the search control state, including the control's currently selected tab, the last executed search, and the results page number.")

You can make the following change in your results code if you wish to call the setLinkTarget method conditionally after calling the startHistoryManagement method.

Find this line in your results code:

  customSearchControl.draw('cse');

Following that line, you could add:

  if (customSearchControl.startHistoryManagement()) {
    customSearchControl.setLinkTarget(
      google.search.Search.LINK_TARGET_SELF);
  }

This page demonstrates history management:
  http://googlecustomsearch.appspot.com/element/history/

For more information about the setLinkTarget and startHistoryManagement methods, please find their descriptions in Custom Search Element JavaScript API documentation:

  https://developers.google.com/custom-search/docs/js/cselement-reference


-- omr