Results 1 to 2 of 2

Thread: google Custom Search api in a js file

Hybrid View

  1. #1
    Join Date
    Apr 2013

    google Custom Search api in a js file

    First I found the demo in google doc:

    HTML Code:
        <title>JSON/Atom Custom Search API Example</title>
        <div id="content"></div>
          function hndlr(response) {
              // handle result
        <script src="https://www.googleapis.com/customsearch/v1?key=KEY&cx=cx&q=cars&callback=hndlr">
    And it works fine.

    But know I want to trigger the "search process" inside a js file say mySearch.js, so how can I get this done ?


    HTML Code:
    var XXXLayer = cc.Layer.extend({
        init:function () {
            var theUrl = 'https://www.googleapis.com/customsearch/v1?key=KEY&cx=cx&q=cars&callback=hndlr';
            // what to do here ???????
            return true;
        hndlr:function(response) {
              // handle result
    Any suggestion would be appreciated thanks

  2. #2
    Join Date
    Jul 2008
    urbana, il
    function loadScript(url, cb) {
    	var x = document.createElement("script");
    	function orsc(e) {
    		e = e || self.event;
    		if (e.type === "load" || {
    			loaded: 1,
    			complete: 1
    		}[x.readyState]) x.onload = x.onreadystatechange = x.onerror = "", cb(null, x)
    	} /* end orsc() */
    	return x.onload = x.onreadystatechange = orsc, x.onerror = cb, x.charset = "utf-8", x.src = url, document.getElementsByTagName("head")[0].appendChild(x)
    } /* end loadScript() */
    i think something like this should work, but you may have to anon pass the handler, or a pointer to it.

    var theUrl = 'https://www.googleapis.com/customsearch/v1?key=KEY&cx=cx&q=cars&callback=hndlr';
        loadScript(theUrl, this.handlr); 
            // what to do here ???????
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center