Integrate search into the header / main page of asp.net MVC site

I want to add a search for my site. I'm thinking of using Google Custom Search ... I need to have a search box in the title bar of the home page, and then a separate search results page when the user searches.

how can I implement this ?, since the code snippet provided by Google seems to be for the results page, I think? Also can I integrate this into a site that is still under construction?

+3
source share
2 answers

I think choosing an iframe option when creating a custom Google search is a way to do this. it separates the code from the search code and the results page

0
source

, Google.

<form id="searchForm" method="get" action="/url-to-your-search-page/" >
  <input id="search" name="search" class="Search" type="text" />
  <input type="submit" value="search" />
</form>

Google .

JavaScript, Google

<script type="text/javascript">
    google.load('search', '1');
    function OnLoad() {
        var s = window.location.search;
        if (s.indexOf('search=') >= 0) {
            s = s.substring(s.indexOf('search=') + 7);
            if (s.indexOf('&') >= 0) {
                s = s.substring(0, s.indexOf('&'));
            }
            s = decodeURIComponent(s.replace('+', ' '));
        }
        else {
            s = "";
        }
        var customSearchControl = new google.search.CustomSearchControl('your-custom-search-id');
        customSearchControl.draw('content');
        customSearchControl.execute(s);
    }
    google.setOnLoadCallback(OnLoad);
</script>

script

<script src="http://www.google.com/jsapi"></script>
+2

Source: https://habr.com/ru/post/1792565/


All Articles