Trình hướng dẫn xem trước
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trình hướng dẫn xem trước được thiết kế để cho phép bạn tích hợp bản xem trước với trang web của mình một cách nhanh chóng, dễ dàng và đáng tin cậy. Bạn có thể nhúng trình xem sách, liên kết đến Tìm kiếm sách hoặc thậm chí thêm cửa sổ "cửa sổ bật lên" xem trước vào trang web của mình — tất cả những gì bạn cần làm là tạo mã và dán mã đó vào trang của mình. Bạn cũng có thể tuỳ chỉnh mã này bằng cách sử dụng một số hàm JavaScript đơn giản.
Trình hướng dẫn xem trước là một thư viện tiện lợi đơn giản mà chúng tôi xây dựng dựa trên các API Đường liên kết động và Trình xem được nhúng. Nếu bạn là một nhà phát triển chuyên nghiệp và đang tìm cách tích hợp tuỳ chỉnh, hãy cân nhắc trực tiếp sử dụng các API cơ bản.
Tạo mã xem trước
Ví dụ về bản xem trước đã tạo
Các ví dụ sau được tạo bằng Trình hướng dẫn xem trước.
Tuỳ chỉnh mã
Ngoài việc sử dụng trình hướng dẫn ở trên, bạn có thể gọi trực tiếp một số chức năng "trợ giúp" đơn giản của JavaScript. Để thực hiện việc này, trước tiên, bạn cần tải thư viện Trình hướng dẫn xem trước. Bạn có thể thực hiện việc này bằng cách thêm thẻ sau vào phần <head>
trên trang:
<script type="text/javascript" src="https://books.google.com/books/previewlib.js"></script>
Sau khi tải thư viện xem trước, bạn có thể gọi bất kỳ hàm nào sau đây từ bên trong thẻ <script>
bên trong <body>
của tài liệu. Ví dụ: nếu muốn chèn nút "Xem trước trên Google", bạn cần đặt mã để thực hiện việc này trong phần tử <script>
tại vị trí mong muốn của nút trên trang.
GBS_setLanguage
GBS_setLanguage(languageCode)
Thay đổi ngôn ngữ của mọi nút hoặc văn bản được thêm sau khi gọi hàm này. Trong đó bao gồm ngôn ngữ của nút "Bản xem trước của Google", ngôn ngữ giao diện của bản xem trước được nhúng, v.v.
Tham số:
string languageCode
– Mã ngôn ngữ RFC 3066 mong muốn (mặc định là "en" cho tiếng Anh). Mã ngôn ngữ hiện được hỗ trợ bao gồm 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, s. , slv, s
GBS_setViewerOptions
GBS_setViewerOptions(optionObj)
Thông số:
Object optionsObj
– Một tập hợp các cặp khoá-giá trị được truyền đến hàm khởi tạo DefaultViewer của API Trình xem được nhúng. Thông thường, chế độ này được sử dụng cho các chế độ tuỳ chỉnh nâng cao.
GBS_setCobrandName
GBS_setCobrandName(cobrandName)
Dành cho các nhà xuất bản trong Chương trình Đối tác sử dụng, chức năng này sẽ đặt trang web Tìm kiếm cùng nhãn hiệu để sử dụng khi chèn đường liên kết xem trước vào trang Tìm kiếm sách. Việc gọi hàm này trước khi chèn nút sẽ đảm bảo rằng người dùng nhìn thấy biểu trưng của đối tác phía trên bản xem trước của Tìm kiếm sách.
GBS_insertEmbeddedViewer
GBS_insertEmbeddedViewer(identifier, opt_width, opt_height)
Chèn bản xem trước của sách được nhúng ở bất cứ nơi nào hàm này được gọi. Nếu không có bản xem trước, sẽ không có trình xem nào hiển thị.
Tham số:
Number opt_width
– Chiều rộng mong muốn của người xem, tính bằng pixel.
Number opt_height
– Chiều cao mong muốn của người xem, tính bằng pixel.
GBS_insertPreviewButtonPopup(identifiers)
Nếu bản xem trước của sách cho phép, hàm này sẽ ghi một nút "Xem trước trên Google". Nhấp vào nút này sẽ mở một "cửa sổ xem trước nổi" ở ngay đầu trang của bạn. Nếu không có bản xem trước, nút này không được vẽ.
Các nhà phát triển tinh vi hơn có thể quan tâm đến API Trình xem được nhúng. Đây là API mà chức năng này sử dụng nội bộ.
Tham số:
string, Array identifier
– URL xem trước hoặc giá trị nhận dạng sách, chẳng hạn như số ISBN, OCLC hoặc LCCN. Hãy xem bài viết Định dạng yêu cầu đường liên kết động. Nếu biết một số giá trị nhận dạng thay thế cho sách, bạn có thể chuyển một dãy các giá trị nhận dạng này và nút sẽ xuất hiện nếu có bản xem trước cho bất kỳ giá trị nào trong số đó.
GBS_insertPreviewButtonLink(identifiers, opt_options)
Nếu bản xem trước của sách cho phép, chức năng này sẽ tạo nút "Xem trước trên Google". Nút này chỉ liên kết đến trang xem trước của cuốn sách. Theo mặc định, đường liên kết này sẽ dẫn đến bản xem trước trên Google Sách, nhưng bạn cũng có thể:
- liên kết đến một URL trên trang web của bạn (URL này nên chứa trình xem được nhúng). Bạn có thể thực hiện việc này bằng cách truyền tuỳ chọn
alternativeUrl
(không bắt buộc).
- liên kết đến phiên bản Đồng thương hiệu của trang xem trước sách, nếu GBS_setCobrandName được gọi trước hàm này.
Nếu người dùng không thấy bản xem trước, thì sẽ không có nút nào hiển thị trên trang.
Tham số:
string, Array identifier
– URL xem trước hoặc giá trị nhận dạng sách, chẳng hạn như số ISBN, OCLC hoặc LCCN. Hãy xem bài viết Định dạng yêu cầu đường liên kết động. Nếu biết một số giá trị nhận dạng thay thế cho sách, bạn có thể chuyển một dãy các giá trị nhận dạng này và nút sẽ xuất hiện nếu có bản xem trước cho bất kỳ giá trị nào trong số đó.
Object opt_options
– không bắt buộc – Bản đồ tên-giá trị dùng để định cấu hình hoạt động của nút. Hiện tại, chúng tôi hỗ trợ một lựa chọn: alternativeUrl
. Ví dụ: để nút Xem trước trên Google liên kết đến một trang xem trước tuỳ chỉnh trên trang web của bạn, bạn chỉ cần truyền giá trị sau làm đối số thứ hai cho GBS_insertPreviewButtonLink
:
{ 'alternativeUrl' : 'http://yoursite.com/your-preview-page' }
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2024-06-28 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2024-06-28 UTC."],[],[],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' } `"]]