Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:48:10+00:00 2026-05-24T13:48:10+00:00

I am using Google Custom Search Engine with their new auto-completion feature. I want

  • 0

I am using Google Custom Search Engine with their new auto-completion feature. I want this whole javascript to be loaded AFTER the page itself is loaded. The original Google code is this:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('search', '1');
  google.setOnLoadCallback(function() {
    google.search.CustomSearchControl.attachAutoCompletion(
      'some-long-unique-id',
      document.getElementById('q'),
      'cse-search-box');
  });
</script>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=cs"></script>

I have transformed this code using tutorial about JS dynamic loading to this code:

(function() {
  var goog = document.createElement('script'); goog.type = 'text/javascript';
  goog.src = 'http://www.google.com/jsapi';
  var cse = document.createElement('script'); cse.type = 'text/javascript';
  cse.src = 'http://www.google.com/cse/brand?form=cse-search-box&lang=cs';
  goog.onload = function() {
    google.load('search', '1');
    google.setOnLoadCallback(function() {
      google.search.CustomSearchControl.attachAutoCompletion(
        'some-long-unique-id',
        document.getElementById('q'),
        'cse-search-box');
    });
  };
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(cse, s);
  s.parentNode.insertBefore(goog, s);
})();

Well, even though I think my solution should work(the same way has Google changed their Analytics on-demand asynchronous code), it doesn’t. The page loads fine and as soon as CSE loads, the page goes blank. Something clears the DOM, I suppose its some kind of “Google thing” ? Can someone bring some light on this problem and possibly a working solution ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:48:11+00:00Added an answer on May 24, 2026 at 1:48 pm

    OK, so by checking Google Loader Developer’s Guide and by lots of trying-and-testing I’ve figured how to change my code so it works as I expected in my question:

    (function() {
      var goog = document.createElement('script'); goog.type = 'text/javascript';
      goog.src = 'http://www.google.com/jsapi';
      goog.onload = function() {
        google.load('search', '1', {"callback": function() {}});
        google.setOnLoadCallback(function() {
          google.search.CustomSearchControl.attachAutoCompletion(
            'some-long-unique-id',
            document.getElementById('q'),
            'cse-search-box');
        });
      };
      var cse = document.createElement('script'); cse.type = 'text/javascript';
      cse.src = 'http://www.google.com/cse/brand?form=cse-search-box&lang=cs';
      var s = document.getElementsByTagName('script')[0]; 
      s.parentNode.insertBefore(cse, s);
      s.parentNode.insertBefore(goog, s);    
    })()
    

    The main thing is this line:

    google.load('search', '1', {"callback": function() {}});
    

    If you don’t specify callback (at least empty function as I do), then the whole page goes blank, when Google’s CSE loads. I have no idea why, but it works fine now with this dummy callback function.

    Hope it helps someone with the same problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're using the Google CSE (Custom Search Engine) paid service to index content on
I'm using Google Engine App with Python. I want to add custom user authentication.
i am using google custom search engine and getting the results in JSON format.for
I am using the C# wrapper Google-API-for-dot-net to query a custom search engine so
I have a webpage that is using Google's custom search engine. I wanted to
I'm new to google custom search and I want to include that in my
I'm using Google Custom Site Search and I want the initial search box on
In the middle of attaching a Google Custom Search Engine onto my page, I
I want to implement the Google custom search API with Greasemonkey, and so far
I want to use google custom search on my site - it's indexed anyway,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.