Ví dụ và bản minh hoạ
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.
Tất cả các ví dụ trong bộ tài liệu về API Trình xem được nhúng đều được liệt kê dưới đây để bạn tham khảo nhanh. Ngoài ra, một số bản minh hoạ bổ sung được đưa vào để minh hoạ các khái niệm nâng cao.
Ví dụ trong Hướng dẫn dành cho nhà phát triển
Những ví dụ cơ bản này xuất hiện trong Hướng dẫn dành cho nhà phát triển và đề cập đến những cách sử dụng phổ biến nhất của Embedded Player API.
- sách đơn giản
Ví dụ "Hello, World" của API Trình xem được nhúng, ví dụ này cho biết cách tải API và vẽ người xem bằng một cuốn sách cụ thể.
- book-language
Ví dụ này cho biết cách thay đổi ngôn ngữ giao diện của người xem, trong trường hợp này là tiếng Bồ Đào Nha (Brazil).
- book-notfound
Phần này cho biết cách thêm hàm callback được gọi khi người xem không thể tải cuốn sách được chỉ định. Bạn có thể xây dựng dựa trên ví dụ này để xử lý linh hoạt các điều kiện như vậy.
- book-Success
Phần này cho biết cách thêm hàm callback được gọi khi người xem đã khởi chạy thành công với một cuốn sách và sẵn sàng thao tác bằng lập trình.
- book-animate
Để minh hoạ cách điều khiển người xem theo phương thức lập trình bằng JavaScript, một bản xem trước sẽ xuất hiện và tự động lật sang trang tiếp theo sau mỗi 3 giây.
Chế độ kiểm soát người xem theo phương thức lập trình
Trình xem cho phép bạn thực hiện với mã hầu hết mọi việc mà người dùng có thể làm bằng cách tương tác với người xem. Các ví dụ bên dưới cho thấy cách điều này có thể hữu ích.
- sách-tương tác-kiểm soát
Ví dụ hoạt động này liệt kê tất cả phương thức tương tác mà người xem hỗ trợ, bao gồm thu phóng, NextPage, goToPage và các hàm đánh dấu.
- book-tương tác-openatpage
Hướng dẫn cách tự động mở trình xem sách trên một trang cụ thể bằng lệnh gọi lại và hàm goToPage.
Kết hợp với Books API và Đường liên kết động
Khi xây dựng các ứng dụng nâng cao, bạn có thể thấy hữu ích khi kết hợp API Trình xem được nhúng với API Sách hoặc tính năng Đường liên kết động. Ví dụ: bạn nên biết trước liệu có sẵn một bản xem trước cụ thể để nhúng hay không (ví dụ: để xác định xem có cho phép người dùng mở cửa sổ xem trước trên trang web của bạn hay không). Hoặc bạn có thể không biết giá trị nhận dạng của một cuốn sách cụ thể và muốn "Tra cứu" trước bằng Books API (API Sách). Các ví dụ dưới đây cho biết cách thực hiện những thao tác này.
- book-dynamiclinks-zippy
Ở đây, chúng ta sẽ kiểm tra xem một cuốn sách có được nhúng trước hay không. Nếu có và chỉ khi có, chúng tôi sẽ hiển thị "zippy xem trước". Khi bạn nhấp vào thẻ này, trang xem trước sách sẽ xuất hiện cùng dòng.
- booksapi-titlesearch
Ví dụ này cho phép bạn mở một trình xem được nhúng chỉ bằng cách nhập cụm từ tìm kiếm về một cuốn sách. Hộp thoại này sẽ tự động hiển thị kết quả có thể nhúng đầu tiên cho truy vấn bạn nhập. Tính năng này sử dụng định dạng đầu ra JSON của Data API để truy cập kết quả tìm kiếm.
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."],[[["\u003cp\u003eThis documentation provides a comprehensive list of examples for Google Books Embedded Viewer API.\u003c/p\u003e\n"],["\u003cp\u003eExamples cover basic viewer setup, language settings, error handling, and programmatic control functionalities.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can learn to integrate the viewer with the Books API and Dynamic Links for advanced functionalities.\u003c/p\u003e\n"],["\u003cp\u003eSample code demonstrates interactions like zooming, navigation, and highlighting within the embedded viewer.\u003c/p\u003e\n"],["\u003cp\u003eUse cases include creating book previews, searching for books, and handling embedding availability.\u003c/p\u003e\n"]]],[],null,["# Examples and Demos\n\nAll of the examples contained within the Embedded Viewer API documentation set are listed below for quick reference. In addition, a number of additional demos are included to illustrate advanced concepts.\n\nExamples from the Developer's Guide\n-----------------------------------\n\nThese basic examples appear in the [Developer's Guide](/books/docs/viewer/developers_guide) and cover the most common uses of the Embedded Viewer API.\n\n- [book-simple](/books/docs/viewer/examples/book-simple) \n The \"Hello, World\" example of the Embedded Viewer API, this example indicates how to load the API and draw a viewer with a particular book.\n- [book-language](/books/docs/viewer/examples/book-language) \n This example shows how to change the viewer's interface language, in this case to Brazilian Portuguese.\n- [book-notfound](/books/docs/viewer/examples/book-notfound) \n This shows how to add a callback function which is called when the viewer could not load the specified book. You can build on this example to gracefully handle such conditions.\n- [book-success](/books/docs/viewer/examples/book-success) \n This shows how to add a callback function which is called when the viewer has successfully initialized with a book and is ready to be manipulated programatically.\n- [book-animate](/books/docs/viewer/examples/book-animate) \n To illustrate how the viewer can be controlled programmatically using JavaScript, a preview is shown which automatically flips to the next page every 3 seconds.\n\nProgrammatic control of the viewer\n----------------------------------\n\nThe viewer allows you to do with code almost anything the user can do by interacting with the the viewer. The examples below show how this might be useful.\n\n- [book-interactions-controls](/books/docs/viewer/examples/book-interactions-controls) \n This working example enumerates all the interaction methods supported by the viewer, including zoom, nextPage, goToPage, and highlighting functions.\n- [book-interactions-openatpage](/books/docs/viewer/examples/book-interactions-openatpage) \n Shows how to automatically open a book viewer on a particular page, using callbacks and the goToPage function.\n\nCombining with the Books API and Dynamic Links\n----------------------------------------------\n\nWhen building advanced applications, you may find it useful to combine\nthe Embedded Viewer API with either the [Books API](/books/docs/v1/getting_started) or the\n[Dynamic Links](/books/docs/dynamic-links)\nfeature. For example, it may be useful to know in advance whether a particular\npreview will be available for embedding (e.g., to determine whether to give the\nuser the option to open a preview window on your site). Or, you may not know the\nidentifier for a particular book, and want to first \"look it up\" using the Books\nAPI. The examples below indicate how to perform these operations.\n\n- [book-dynamiclinks-zippy](/books/docs/viewer/examples/book-dynamiclinks-zippy) \n Here we check whether a book is available for embedding first. If and only if it is available, we render a \"preview zippy,\" which, when clicked, shows the book preview inline.\n- [booksapi-titlesearch](/books/docs/viewer/examples/booksapi-titlesearch) \n This example allows you open an embedded viewer by simply entering a search query for a book. It will automatically show the first embeddable result for the query you enter. This uses the JSON output format of the Data API to access the search results."]]