ดูตัวอย่างวิซาร์ด
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตัวช่วยแสดงตัวอย่างได้รับการออกแบบมาเพื่อให้คุณรวมตัวอย่างกับเว็บไซต์ของคุณได้อย่างรวดเร็ว ง่ายดาย และเชื่อถือได้ คุณสามารถฝังเครื่องมือดูหนังสือ ลิงก์ไปยัง Book Search หรือแม้กระทั่งเพิ่มหน้าต่าง "ป๊อปอัป" หน้าตัวอย่างลงในเว็บไซต์ของคุณ สิ่งที่คุณต้องทำก็คือสร้างโค้ดและวางโค้ดลงในหน้าเว็บของคุณ นอกจากนี้คุณยังสามารถปรับแต่งโค้ดนี้โดยใช้ฟังก์ชัน JavaScript ง่ายๆ บางอย่าง
วิซาร์ดการแสดงตัวอย่างเป็นไลบรารีอำนวยความสะดวกที่เรียบง่ายซึ่งเราสร้างขึ้นโดยต่อยอดมาจาก API ของลิงก์แบบไดนามิกและผู้ดูแบบฝัง หากคุณเป็นนักพัฒนาซอฟต์แวร์ขั้นสูงที่ต้องการการผสานรวมที่กำหนดเอง โปรดลองใช้ API ที่เกี่ยวข้องโดยตรง
สร้างโค้ดตัวอย่าง
ตัวอย่างตัวอย่างที่สร้างขึ้น
ตัวอย่างต่อไปนี้สร้างขึ้นโดยใช้วิซาร์ดการแสดงตัวอย่าง
ปรับแต่งโค้ด
นอกจากการใช้วิซาร์ดข้างต้นแล้ว คุณยังสามารถเรียกใช้ฟังก์ชัน "ตัวช่วย" ของ JavaScript โดยตรงได้โดยตรงอีกด้วย โดยคุณควรโหลดไลบรารีวิซาร์ดการแสดงตัวอย่างก่อน วิธีหนึ่งที่ทำได้คือการเพิ่มแท็กต่อไปนี้ลงในส่วน <head>
ของหน้าเว็บ
<script type="text/javascript" src="https://books.google.com/books/previewlib.js"></script>
เมื่อโหลดไลบรารีตัวอย่างแล้ว คุณจะสามารถเรียกใช้ฟังก์ชันใดก็ได้ต่อไปนี้จากภายในแท็ก <script>
ภายใน <body>
ของเอกสารของคุณ ตัวอย่างเช่น หากต้องการแทรกปุ่ม "ตัวอย่างโดย 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-BR, pt-s,
GBS_setViewerOptions
GBS_setViewerOptions(optionObj)
พารามิเตอร์:
Object optionsObj
- ชุดคู่คีย์-ค่าที่ส่งไปยังตัวสร้าง DefaultViewer ของ Embedded Viewer API โดยทั่วไป ตัวเลือกนี้ใช้สำหรับการปรับแต่งขั้นสูง
GBS_setCobrandName
GBS_setCobrandName(cobrandName)
ฟังก์ชันนี้มีไว้สำหรับผู้เผยแพร่เนื้อหาในโปรแกรมพาร์ทเนอร์ โดยจะตั้งค่าเว็บไซต์การค้นหาแบบร่วมแบรนด์ให้ใช้เมื่อแทรกลิงก์ตัวอย่างไปยัง Book Search การเรียกใช้ฟังก์ชันนี้ก่อนแทรกปุ่มช่วยให้แน่ใจว่าผู้ใช้จะเห็นโลโก้ของพาร์ทเนอร์เหนือตัวอย่างใน Book Search
GBS_insertEmbeddedViewer
GBS_insertEmbeddedViewer(identifier, opt_width, opt_height)
แทรกตัวอย่างหนังสือแบบฝังในตำแหน่งที่มีการเรียกใช้ฟังก์ชันนี้ หากตัวอย่างไม่พร้อมใช้งาน จะไม่มีผู้ชมปรากฏขึ้น
พารามิเตอร์มีดังนี้
Number opt_width
- ความกว้างของผู้ชมตามต้องการเป็นพิกเซล
Number opt_height
- ความสูงที่ต้องการของผู้ชมในหน่วยพิกเซล
GBS_insertPreviewButtonPopup(identifiers)
หากมีตัวอย่างหนังสือให้ใช้งาน ฟังก์ชันนี้จะเขียนปุ่ม "ตัวอย่างหนังสือของ Google" ออกมา การคลิกปุ่มนี้จะเปิดหน้าต่าง "แสดงตัวอย่างแบบลอย" ที่ด้านบนของหน้าขึ้นมา หากไม่มีหน้าตัวอย่าง หมายความว่าจะไม่มีการวาดปุ่มดังกล่าว
นักพัฒนาซอฟต์แวร์ที่มีความเชี่ยวชาญเพิ่มขึ้นอาจสนใจใช้ Embedded Viewer API ซึ่งฟังก์ชันนี้ใช้เป็นการภายใน
พารามิเตอร์มีดังนี้
string, Array identifier
- URL ตัวอย่างหรือตัวระบุหนังสือ เช่น หมายเลข ISBN, OCLC หรือ LCCN ดูรูปแบบคำขอลิงก์แบบไดนามิก ถ้าคุณรู้จักตัวระบุทางเลือกต่างๆ ของหนังสือ คุณสามารถส่งอาร์เรย์ของตัวระบุเหล่านี้ และปุ่มนี้จะปรากฏขึ้นหากมีตัวอย่างสำหรับสัญลักษณ์ตัวใดตัวหนึ่ง
GBS_insertPreviewButtonLink(identifiers, opt_options)
หากมีตัวอย่างหนังสือให้ใช้งาน ฟังก์ชันนี้จะเขียนปุ่ม "ตัวอย่างหนังสือของ Google" ออกมา เพื่อเป็นหน้าตัวอย่างของหนังสือ โดยค่าเริ่มต้น ลิงก์นี้จะลิงก์ไปยังการแสดงตัวอย่างใน Google Books แต่คุณยังทําสิ่งต่อไปนี้ได้
- ลิงก์ไปยัง URL บนเว็บไซต์ของคุณ (ซึ่งควรมีโปรแกรมดูแบบฝัง) ซึ่งทำได้โดยการส่งตัวเลือก
alternativeUrl
ที่ไม่บังคับ
- ลิงก์ไปยังหน้าตัวอย่างหนังสือแบบร่วมแบรนด์ หากมีการเรียก GBS_setCobrandName ก่อนฟังก์ชันนี้
หากผู้ใช้ไม่แสดงตัวอย่าง ก็จะไม่มีการวาดปุ่มบนหน้าเว็บ
พารามิเตอร์มีดังนี้
string, Array identifier
- URL ตัวอย่างหรือตัวระบุหนังสือ เช่น หมายเลข ISBN, OCLC หรือ LCCN ดูรูปแบบคำขอลิงก์แบบไดนามิก ถ้าคุณรู้จักตัวระบุทางเลือกต่างๆ ของหนังสือ คุณสามารถส่งอาร์เรย์ของตัวระบุเหล่านี้ และปุ่มนี้จะปรากฏขึ้นหากมีตัวอย่างสำหรับสัญลักษณ์ตัวใดตัวหนึ่ง
Object opt_options
- ไม่บังคับ - การแมปชื่อ-ค่าที่ใช้เพื่อกำหนดค่าการทำงานของปุ่ม ปัจจุบันระบบรองรับตัวเลือกเดียวคือ alternativeUrl
เช่น หากต้องการให้ปุ่มแสดงตัวอย่างของ Google ลิงก์กับหน้าตัวอย่างที่กำหนดเองในเว็บไซต์ ให้ส่งข้อมูลต่อไปนี้เป็นอาร์กิวเมนต์ที่ 2 ไปยัง GBS_insertPreviewButtonLink
{ 'alternativeUrl' : 'http://yoursite.com/your-preview-page' }
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-06-28 UTC
[null,null,["อัปเดตล่าสุด 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' } `"]]