预览向导
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
预览向导旨在帮助您快速、轻松、可靠地将预览与您的网站集成。您可以嵌入图书查看器、链接到图书搜索,甚至可以向您的网站添加预览“弹出式窗口”窗口,您只需生成代码并将其粘贴到您的网页中即可。您还可以使用一些简单的 JavaScript 函数来自定义此代码。
预览向导是一个简单的便捷库,我们以 Dynamic Links 和 Embedded Viewer API 为基础构建而成。如果您是需要自定义集成的高级开发者,请考虑直接使用底层 API。
生成预览代码
生成的预览示例
以下示例是使用预览向导生成的。
自定义您的代码
除了使用上面的向导,您还可以直接调用一些简单的 JavaScript“帮助程序”函数。为此,您应首先加载预览向导库。一种方法是将以下代码添加到网页的 <head>
部分:
<script type="text/javascript" src="https://books.google.com/books/previewlib.js"></script>
加载预览库后,您可以从文档的 <body>
内的 <script>
标记内调用以下任一函数。例如,如果您要插入“Google 预览”按钮,则需要将代码放置在 <script>
元素中,并将其放在页面中该按钮的所需位置。
GBS_setLanguage
GBS_setLanguage(languageCode)
用于更改在调用此函数后添加的任何按钮或文本的语言。其中包括“Google 预览”按钮的语言、嵌入的预览的界面语言等。
参数:
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-uk、pt-BR、pt-ru
GBS_setViewerOptions
GBS_setViewerOptions(optionObj)
GBS_setCobrandName
GBS_setCobrandName(cobrandName)
此函数旨在供合作伙伴计划中的出版商使用,用于设置在向图书搜索中插入任何预览链接时所使用的联合品牌搜索网站。在插入按钮之前调用此函数可确保用户在图书搜索预览上方看到合作伙伴的徽标。
GBS_insertEmbeddedViewer
GBS_insertEmbeddedViewer(identifier, opt_width, opt_height)
在调用此函数的位置插入嵌入式图书预览。如果无法预览,则系统不会显示任何查看器。
参数:
Number opt_width
- 所需的查看器宽度(以像素为单位)。
Number opt_height
- 查看器所需的高度(以像素为单位)。
GBS_insertPreviewButtonPopup(identifiers)
参数:
string, Array identifier
- 试阅网址或图书标识符,例如 ISBN、OCLC 或 LCCN 编号。请参阅 Dynamic Links 请求格式。如果您知道该图书的多个替代标识符,可以传递一组这些标识符,当其中任何一个标识符可供预览时,系统就会显示相应按钮。
GBS_insertPreviewButtonLink(identifiers, opt_options)
如果可以进行图书预览,则此函数会写出“Google 预览”按钮,点击该按钮会直接链接到相应图书的预览页面。默认情况下,此链接会链接到 Google 图书上的试阅部分,但您也可以:
- 指向您网站上某个网址(其中应该包含一个嵌入式查看器)的链接。为此,您可以传递可选的
alternativeUrl
选项。
- 会链接到图书预览页的联合品牌版本(前提是在此函数之前调用了 GBS_setCobrandName)。
如果用户无法预览,则不会在页面上绘制任何按钮。
参数:
string, Array identifier
- 试阅网址或图书标识符,例如 ISBN、OCLC 或 LCCN 编号。请参阅 Dynamic Links 请求格式。如果您知道该图书的多个替代标识符,可以传递一组这些标识符,当其中任何一个标识符可供预览时,系统就会显示相应按钮。
Object opt_options
- 可选 - 用于配置按钮行为的名称值映射。目前支持一种选项:alternativeUrl
。例如,如需将“Google 预览”按钮链接到您网站上的自定义预览页面,只需将以下内容作为第二个参数传递给 GBS_insertPreviewButtonLink
即可:
{ 'alternativeUrl' : 'http://yoursite.com/your-preview-page' }
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-06-28。
[null,null,["最后更新时间 (UTC):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' } `"]]