I am trying to fetch book cover,title and author using openlibrary.org api. But i can't do it.When i click the search this image appears as shown in screenshot.Also i am providing some source code.And i am getting error "Refused to execute script from 'http://ia800609.us.archive.org/view_archive.php?archive=/28/items/olcovers121/olcovers121-M.zip&file=1212744-M.jpg&ext=' because its MIME type ('image/jpeg') is not executable." Please provide some suggetion regarding solving the error.Thanks in advance.
function search_google_books() {
var script = document.createElement('script');
var isbn = document.forms[0].isbn;
if (isbn && isbn.value != '') {
document.getElementById('thumbnail').innerHTML = '<img src="./loading.gif" />';
script.src = 'http://covers.openlibrary.org/b/isbn/' + isbn.value + '-M.jpg';
document.body.appendChild(script);
} else {
alert('Please input ISBN!');
}
}
function show_bookcover(booksInfo) {
var link = '<span class="nolink">No image available...</span>';
for (i in booksInfo.items) {
var book = booksInfo.items[i]
var image = book.volumeInfo.imageLinks;
if (image && image.thumbnail != undefined) {
var thumbnail = image.thumbnail.replace('zoom=5', 'zoom=1');
if (document.location.protocol == 'https:') {
var parser = document.createElement('a');
parser.href = thumbnail;
parser.protocol = 'https:';
parser.hostname = 'encrypted.google.com';
thumbnail = parser.href;
}
link = '<img src="' + thumbnail + '" />';
if (book.accessInfo && book.accessInfo.viewability != "NO_PAGES") {
var preview = book.volumeInfo.previewLink;
link += '<br />';
}
}
link += '<br />Title: ' + book.volumeInfo.title;
if (book.volumeInfo.authors.length > 0) {
link += '<br />Author: ' + book.volumeInfo.authors.join("; ");
}
}
document.getElementById('thumbnail').innerHTML = link;
} <
#thumbnail {
margin: 1em 4em;
}
<html>
<head>
<title>Test for Open Search API: book cover</title>
</head>
<body>
<div id="form">
<form>
Enter ISBN: <input type="text" size="40" placeholder="ISBN" value="9780415261876" name="isbn" id="isbn" />
<button onclick="javascript:search_google_books();
return false;">Search</button>
</form>
</div>
<div id="thumbnail"></div>
</body>
When you just want to fetch the associated book cover image, a few minor modifications in your code would be enough:
function search_google_books() {
var isbn = document.forms[0].isbn;
if (isbn && isbn.value != '') {
document.getElementById('thumbnail').innerHTML = '<img src="http://covers.openlibrary.org/b/isbn/' + isbn.value + '-M.jpg" />';
} else {
alert('Please input ISBN!');
}
}
#thumbnail {
margin: 1em 4em;
}
<html>
<head>
<title>Test for Open Search API: book cover</title>
</head>
<body>
<div id="form">
<form>
Enter ISBN: <input type="text" size="40" placeholder="ISBN" value="9780415261876" name="isbn" id="isbn" />
<button onclick="javascript:search_google_books();
return false;">Search</button>
</form>
</div>
<div id="thumbnail"></div>
</body>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments