預覽精靈
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
透過 Preview 精靈,您可以快速、輕鬆且穩定地將預覽整合至網站。您還可以在書籍檢視器中嵌入書籍檢視器、連結至圖書搜尋,甚至新增預覽「彈出式視窗」視窗到網站上。方法很簡單,只要產生程式碼,然後貼到您的網頁上即可。此外,您也可以使用部分簡單的 JavaScript 函式自訂此程式碼。
預覽精靈是以 Dynamic Links 和 Embedded Viewer API 為基礎建構而成的簡易型程式庫。如果您是需要自訂整合的進階開發人員,請考慮直接使用基礎 API。
產生預覽程式碼
產生的預覽範例
下列範例是使用 Preview Wizard 產生的。
自訂程式碼
除了使用上述精靈以外,您也可以直接呼叫一些簡單的 JavaScript「helper」函式。為此,您必須先載入預覽精靈程式庫。其中一種方法是在網頁的 <head>
部分新增以下標記:
<script type="text/javascript" src="https://books.google.com/books/previewlib.js"></script>
載入預覽程式庫後,您可以在文件 <body>
內的 <script>
標記內呼叫下列任何函式。舉例來說,如果您想插入「Google 預覽」按鈕,可以將程式碼放在頁面內所需位置的 <script>
元素中。
GBS_setLanguage
GBS_setLanguage(languageCode)
呼叫此函式後新增的任何按鈕或文字,變更語言。包括 [Google Preview] 按鈕的語言、內嵌預覽的介面語言等。
參數:
string languageCode
- 所需的 RFC 3066 語言代碼 (預設為「en」表示英文)。目前支援的語言代碼包括 hy、bg、ca、zh-CN、zh-TW、hr、cs、da、nl、en、fil、fi、fr、de、el、hi、hu、is、id、in、it、ja、ko、lv、lt、no、pl、pt-k、pt、
GBS_setViewerOptions
GBS_setViewerOptions(optionObj)
GBS_setCobrandName
GBS_setCobrandName(cobrandName)
這項功能適合合作夥伴計畫的出版商使用,可設定在將任何預覽連結插入「Google 圖書搜尋」時,要使用的聯合品牌搜尋網站。在插入按鈕前呼叫此函式,可確保使用者在書籍搜尋預覽上方看到合作夥伴的標誌。
GBS_insertEmbeddedViewer
GBS_insertEmbeddedViewer(identifier, opt_width, opt_height)
在所有呼叫此函式的位置插入內嵌書籍預覽。如果無法預覽,就不會顯示檢視器。
參數:
Number opt_width
- 所需的檢視器寬度 (以像素為單位)。
Number opt_height
- 所需的檢視器高度,以像素為單位。
GBS_insertPreviewButtonPopup(identifiers)
參數:
string, Array identifier
- 預覽網址或書籍 ID,例如 ISBN、OCLC 或 LCCN 編號。請參閱「Dynamic Links 要求格式」。如果您知道書籍的幾種替代 ID,可以傳遞這些 ID 的陣列,如果其中一個 ID 提供試閱內容,就會顯示這個按鈕。
GBS_insertPreviewButtonLink(identifiers, opt_options)
如果有書籍試閱內容,這個函式會撰寫 [Google Preview] 按鈕,直接連結至書籍的預覽頁面。根據預設,這個連結會導向 Google 圖書的試閱內容,但你也可以:
- 連結到網站中的網址 (如此應該會包含嵌入式檢視器)。只要傳送選用的
alternativeUrl
選項即可。
- 連結至書籍預覽網頁的聯合品牌版本 (如果在這個函式之前呼叫 GBS_setCobrandName)。
如果使用者無法提供預覽,頁面上就不會顯示任何按鈕。
參數:
string, Array identifier
- 預覽網址或書籍 ID,例如 ISBN、OCLC 或 LCCN 編號。請參閱「Dynamic Links 要求格式」。如果您知道書籍的幾種替代 ID,可以傳遞這些 ID 的陣列,如果其中一個 ID 提供試閱內容,就會顯示這個按鈕。
Object opt_options
- 選用:用於設定按鈕行為的名稱/值對應。目前支援一個選項:alternativeUrl
。舉例來說,若要將 Google 預覽按鈕連結到您網站上的自訂預覽網頁,只要將下列程式碼做為第二個引數傳遞至 GBS_insertPreviewButtonLink
即可:
{ 'alternativeUrl' : 'http://yoursite.com/your-preview-page' }
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-06-28 (世界標準時間)。
[null,null,["上次更新時間:2024-06-28 (世界標準時間)。"],[],[],null,["# Preview Wizard\n\nThe Preview Wizard is designed to let you quickly, easily, and reliably integrate previews with your site. You can embed a book viewer, link to Book Search, or even add a preview \"popup\" window to your site---all you need to do is [generate the code](#generateCode) and paste it onto your page. You can also [customize this code](#customizeYourCode) using some simple JavaScript functions.\n\nThe Preview Wizard is a simple convenience library we built on top of our [Dynamic Links](/books/docs/dynamic-links) and [Embedded Viewer](/books/docs/viewer/developers_guide) APIs. If you're an advanced developer looking for customized integration, consider\nusing the underlying APIs directly.\n\nGenerate your preview code\n--------------------------\n\n#### Enter book identifiers\n\nTell us all the ISBNs or other identifiers you know of for this book. If we can find a preview associated with any of these numbers, we can make it available to your site's users:\n\n|--------------------------------------|---|\n| ISBN OCLC number LCCN Book Search ID | |\n| ISBN OCLC number LCCN Book Search ID | |\n| ISBN OCLC number LCCN Book Search ID | |\n\n[Enter more identifiers...](about:invalid#zGoSafez)\n\n#### Choose how to show the book preview\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| If a preview is available for this book, what should the user see on your page? |---|------------------------------------------------------------------------| | | An embedded book viewer. Viewer size: pixels wide, pixels high | | | A button that opens a floating book viewer. | | | A button that links to the book's preview page on Book Search. | | | A button that goes to a custom preview page on your site. Preview URL: | If no preview can be found for the specified book(s), the preview or button will be automatically disabled and nothing will appear. | |\n\n#### Select your language\n\nChinese (Simplified) Chinese (Traditional) Dutch English French German Italian Japanese Portuguese (Brazilian) Russian Spanish\n\n#### Generate code for your web page\n\nExamples of generated previews\n------------------------------\n\nThe following examples were generated using the Preview Wizard.\n\n- [previewwizard-embed](/books/examples/previewwizard-embed): Embeds a book viewer on the page.\n- [previewwizard-popup](/books/examples/previewwizard-popup): Adds a button that can be clicked to open a floating preview over the page.\n- [previewwizard-linktogbs](/books/examples/previewwizard-linktogbs): Inserts a button that links to the preview on the Book Search site.\n- [previewwizard-customurl](/books/examples/previewwizard-customurl): Shows a button that goes to a specific URL.\n\nCustomize your code\n-------------------\n\nIn addition to using the wizard above, you can call some simple JavaScript \"helper\" functions directly. To do this, you should first load the Preview Wizard library. One way to do this is by adding the following tag to the `\u003chead\u003e` section of your page: \n\n```\n\u003cscript type=\"text/javascript\" src=\"https://books.google.com/books/previewlib.js\"\u003e\u003c/script\u003e\n```\n\nHaving loaded the preview library, you can then call any of the following functions from within `\u003cscript\u003e` tags inside your document's `\u003cbody\u003e`. For example, if you'd like to insert the \"Google Preview\" button, you'd put the code to do so in a `<script\u003e` element at the button's desired position within the page.\n\n### GBS_setLanguage\n\n```\nGBS_setLanguage(languageCode)\n```\n\nChanges the language of any buttons or text added after this function is called. This includes the language of the \"Google Preview\" button, the interface language of the embedded preview, and so on.\n\n\u003c!-- --\u003e\n\n**Parameters:** *string*` languageCode ` - The desired RFC 3066 language code (default is 'en' for English). Currently supported language codes include hy, bg, ca, zh-CN, zh-TW, hr, cs, da, nl, en, fil, fi, fr, de, el, hi, hu, is, id, in, it, ja, ko, lv, lt, no, pl, pt-BR, pt-PT, ro, ru, sr, sk, sl, es, sv, th, tr, uk, and vi.\n\n### GBS_setViewerOptions\n\n```\nGBS_setViewerOptions(optionObj)\n```\n\n**Parameters:** *Object*` optionsObj ` - A set of key-value pairs passed to the Embedded Viewer API's [DefaultViewer constructor](/books/docs/viewer/reference#google.books.DefaultViewer). Typically, this is used for advanced customizations.\n\n### GBS_setCobrandName\n\n```\nGBS_setCobrandName(cobrandName)\n```\n\nIntended for use by publishers in the [Partner Program](https://books.google.com/partner), this function sets the [Co-Branded Search](https://books.google.com/support/partner/bin/answer.py?hl=en&answer=65113) site to be used when inserting any preview links to Book Search. Calling this function before inserting a button ensures that users see the partner's logo above the Book Search previews.\n\n\u003c!-- --\u003e\n\n**Parameters:** *string*` cobrandName ` - The cobrand name to be added to any Book Search URLs. This is typically what comes after `/p/` in existing Co-Branded Search preview URLs.\n- For example, setting the value to `sup` will send the user to links like \n `https://books.google.com/books/p/sup?id=Q8ysL64pM54C&printsec=frontcover` \n rather than the default \n `https://books.google.com/books?id=Q8ysL64pM54C&printsec=frontcover`\n\n### GBS_insertEmbeddedViewer\n\n```\nGBS_insertEmbeddedViewer(identifier, opt_width, opt_height)\n```\n\nInserts an embedded book preview wherever this function is called. If the preview is unavailable, no viewer is shown.\n\n\u003c!-- --\u003e\n\n**Parameters:** *string*` identifier ` - A preview URL or book identifier such as an ISBN, OCLC, or LCCN number. See [Dynamic Links request format](/books/docs/dynamic-links#requestFormat).\n\u003c!-- --\u003e\n\n*Number*` opt_width ` - The desired width of the viewer, in pixels.\n\u003c!-- --\u003e\n\n*Number*` opt_height ` - The desired height of the viewer, in pixels.\n\n### GBS_insertPreviewButtonPopup\n\n```\nGBS_insertPreviewButtonPopup(identifiers)\n```\n\nIf the book preview is available, this function writes out a \"Google Preview\" button. Clicking this button opens a \"floating preview window\" right on top of your page. If no preview is available, the button is not drawn.\n- More sophisticated developers may be interested in the [Embedded Viewer API](/books/docs/viewer/developers_guide), which this function uses internally.\n\n\u003c!-- --\u003e\n\n**Parameters:** *string, Array*` identifier ` - A preview URL or book identifier such as an ISBN, OCLC, or LCCN number. See [Dynamic Links request format](/books/docs/dynamic-links#requestFormat). If you know of several alternative identifiers for the book, you can pass an array of these identifiers, and the button will appear if a preview is available for any one of them.\n\n### GBS_insertPreviewButtonLink\n\n```\nGBS_insertPreviewButtonLink(identifiers, opt_options)\n```\n\nIf the book preview is available, this function writes out a \"Google Preview\" button that simply links off to a preview page for the book. By default, this links to the preview on Google Books, but you can also:\n- link to a URL on your site (which should, in turn contain an embedded viewer). You can do this by passing an optional `alternativeUrl` option.\n- link to a Co-Branded version of the book preview page, if [GBS_setCobrandName](#GBS_setCobrandName) is called before this function.\nIf no preview is available to the user, no button is drawn onto the page.\n\n\u003c!-- --\u003e\n\n**Parameters:** *string, Array*` identifier ` - A preview URL or book identifier such as an ISBN, OCLC, or LCCN number. See [Dynamic Links request format](/books/docs/dynamic-links#requestFormat). If you know of several alternative identifiers for the book, you can pass an array of these identifiers, and the button will appear if a preview is available for any one of them.\n\u003c!-- --\u003e\n\n*Object*` opt_options ` - *optional* - A name-value map used to configure the behavior of the button. Currently one option is supported: `alternativeUrl`. For example, to have the Google Preview button link to a custom preview page on your site, simply pass the following as a second argument to `GBS_insertPreviewButtonLink`: \n` { 'alternativeUrl' : 'http://yoursite.com/your-preview-page' } `"]]