<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |