Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Search API Sample</title>
    <!-- Google Search是從「Google Web Search API Developer's Guide( https://developers.google.com/web-search/docs/ )」範例改寫而成的 -->
    <!-- 首先Load Google Web Search API  -->
    <script src="https://www.google.com/jsapi" type="text/javascript"></script>
 
 
    <script language="Javascript" type="text/javascript">
    
    // Load Google Search Module
    google.load('search', '1');
    function OnLoad() {
      // Create a search control
      var searchControl = new google.search.SearchControl();
      // site restricted web search
      var siteSearch = new google.search.WebSearch();
      siteSearch.setSiteRestriction("www.appledaily.com.tw/appledaily/article/supplement/");
      searchControl.addSearcher(siteSearch);
      // tell the searcher to draw itself and tell it where to attach
      searchControl.draw(document.getElementById("searchframe"));
      
      // execute an inital search
      searchControl.execute("武陵農場");
      // use the search control to provide what we need
      searchControl.setSearchCompleteCallback(this, OnSearchComplete);
    }
    // 當搜尋完成, 將原搜尋結果顯示取代為自訂的顯示格式(並在網址前段加上Instapaper將超連結的網頁內容轉換成適合手機觀看)
    // 這個function的相關寫法還可以參考 http://tools.assembla.com/svn/wellness/test/g.html
    // 這個function的相關寫法還可以參考 http://plugins.svn.wordpress.org/infolinks/trunk/infolink.js?p=160750
    // 這個function的相關寫法還可以參考 http://jblgadgettest.googlecode.com/svn/trunk/search.html
    OnSearchComplete = function(sc, searcher) {
      if ( searcher.results && searcher.results.length > 0) 
        {
         var contentDiv = document.getElementById('searchframe');
         // contentDiv.innerHTML = '';
         var str = '';
         for (var i = 0; i < searcher.results.length; i++) {
             // GwebResuts屬性可參考 https://developers.google.com/web-search/docs/reference?hl=zh-TW#_intro_GResult
             str += '<p><a href="http://www.instapaper.com/m?u=' +  searcher.results[i].url + '">';
             str +=  searcher.results[i].title + '</a><p>'
            }
         contentDiv.innerHTML = str;
        }
    }
    
    // To register the specified handler function to be called once the document loads
    google.setOnLoadCallback(OnLoad);
    </script>
  </head>
  <body>
    <div id="searchframe">Loading</div>
  </body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers