Jump to content

Widget:Google Books: Difference between revisions

From 313FILES
No edit summary
No edit summary
Line 6: Line 6:
To use this widget, add the following code to your wiki page:
To use this widget, add the following code to your wiki page:


<pre>
{{#widget:Google_Books
|id=BOOK_ID
|width=600
|height=500
}}
</pre>
Parameters:
* '''id''' - The Google Books ID (required)
* '''width''' - Width of the embedded viewer in pixels (optional, default: 600)
* '''height''' - Height of the embedded viewer in pixels (optional, default: 500)
== Copy to your site ==
To use this widget on your site, install [https://www.mediawiki.org/wiki/Extension:Widgets MediaWiki Widgets extension] and copy the [{{fullurl:{{FULLPAGENAME}}|action=edit}} complete source code] of this page to your wiki as page '''{{FULLPAGENAME}}'''.
</noinclude>
</noinclude>
<includeonly>
<includeonly>
<!-- This is important: Place the viewer exactly where we want it -->
<!-- Direct iframe embed - simpler and more reliable -->
<div style="position:relative; width:<!--{$width|escape:'html'|default:'600'}-->px; height:<!--{$height|escape:'html'|default:'500'}-->px; margin:1em 0;">
<iframe frameborder="0"  
  <script type="text/javascript" src="https://books.google.com/books/previewlib.js"></script>
        scrolling="no"
  <script type="text/javascript">
        style="border:0px"  
  /* <![CDATA[ */
        src="https://books.google.com/books?id=<!--{$id|escape:'html'}-->&lpg=PP1&dq=<!--{$id|escape:'html'}-->&pg=PP1&output=embed"  
  (function() {
        width="<!--{$width|escape:'html'|default:'600'}-->"
    var bId = "<!--{$id|escape:'html'}-->";
        height="<!--{$height|escape:'html'|default:'500'}-->">
    var width = <!--{$width|escape:'html'|default:'600'}-->;
</iframe>
    var height = <!--{$height|escape:'html'|default:'500'}-->;
   
    // Create an inline placeholder
    document.write('<div id="gbPreviewContainer_' + bId + '" style="width:' + width + 'px; height:' + height + 'px;"></div>');
   
    // Insert the viewer at the placeholder location
    function insertViewer() {
      if (typeof GBS_insertEmbeddedViewer === 'function') {
        GBS_insertEmbeddedViewer(bId, width, height);
      } else {
        // Retry if API not loaded yet
        setTimeout(insertViewer, 100);
      }
    }
   
    insertViewer();
  })();
  /* ]]> */
  </script>
</div>
</includeonly>
</includeonly>

Revision as of 15:32, 10 March 2025

This widget allows you to embed Google Books on your wiki page. Originally created by Arv and adapted by FrancisFranck.

Using this widget

To use this widget, add the following code to your wiki page:

{{#widget:Google_Books
 |id=BOOK_ID
 |width=600
 |height=500
}}

Parameters:

  • id - The Google Books ID (required)
  • width - Width of the embedded viewer in pixels (optional, default: 600)
  • height - Height of the embedded viewer in pixels (optional, default: 500)

Copy to your site

To use this widget on your site, install MediaWiki Widgets extension and copy the complete source code of this page to your wiki as page Widget:Google Books.