Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Google Books JS problem

    Hi All, I'm new to JS, and I'm trying to make google books previewed on my website. It works fine but if the book(ISBN) is not available for previewing, which only gives me nothing on the page

    What I need is it give me a alert, or some echos,which tells something like "this book is not available for Previewing" when the ISBN is not found. Here is my code used on a php, and also a JS with the link. http://www.google.com/jsapi

    <script type="text/javascript" src="js/jsapi.js"></script>
    <script type="text/javascript">
    google.load("books", "0", {"language" : "es-ES"});

    function initialize() {
    var viewer = new google.books.DefaultViewer(document.getElementById('viewerCanvas'));
    viewer.load('ISBN:<?php echo $ISBN; ?>');
    }
    google.setOnLoadCallback(initialize);
    </script>
    </head>

    <body>
    <div id="viewerCanvas" style="width: 600px; height: 700px"></div>
    </body>

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    help please.

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    what is the error that it throws if there is no ISBN? I imagine you could do something like this:

    Code:
    function initialize() {
    if (!ISBN) {
    //show some div saying "this book is not available for Previewing"
    } else {
    var viewer = new google.books.DefaultViewer(document.getElementById('viewerCanvas'));
    viewer.load('ISBN:<?php echo $ISBN; ?>');
         }
    }

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    oops. I mean:

    Code:
    var ISBN="<?php echo $ISBN; ?>"
    
    function initialize() {
    if (!ISBN) {
    //show some div saying "this book is not available for Previewing"
    } else {
    var viewer = new google.books.DefaultViewer(document.getElementById('viewerCanvas'));
    viewer.load('ISBN:<?php echo $ISBN; ?>');
         }
    }

  • #5
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks xelawho, I mean everybook already has a ISBN in my DB, but not all of them are available for Previewing through GOOGLE API, only some of them.When I browse these books which were not available, the window returns me nothing but a white page. I want to say something on that page instead of nothing. :>

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    right.

    so when you try to open a book and google doesn't have it, does firebug show an error? do you by chance have a link to your page?

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    never mind - it's here in the documentation...

    Code:
    function alertNotFound() {
      alert("could not embed the book!");
    }
    
    function initialize() {
      var viewer = new google.books.DefaultViewer(document.getElementById('viewerCanvas'));
      viewer.load('ISBN:<?php echo $ISBN; ?>', alertNotFound);
    }
    of course, you could swap the alert for whatever you wanted...

  • Users who have thanked xelawho for this post:

    pluszone (09-27-2011)

  • #8
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks again. It works this time, and I just followed the "Handling failed initializations" of GOOGLE DEV Guide, everything is right there.
    function alertNotFound() {
    alert("could not embed the book!");
    }
    // plus
    viewer.load('ISBN:<?php echo $id; ?>', alertNotFound);
    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •