0

Hi I want to add google book preview button to my website. Its code is something like :

<script> GBS_setLanguage('en');</script>            
<script>GBS_insertPreviewButtonPopup('ISBN:0596009208');</script>

Now the problem is I get the ISBN number from the previous page. So I have to include this in C# code on the page. So how this can be done ? I tried doing it but it just does not compile

Saurabh
  • 5,661
  • 2
  • 26
  • 32
Anuj Kulkarni
  • 2,261
  • 5
  • 32
  • 42

2 Answers2

0

Used this code to do what I wanted... But it places the script/ google preview button (in my case) to either header or the footer . But no other way to do this.

         HtmlGenericControl script1 = new HtmlGenericControl("script");
        script1.Attributes.Add("type", "text/javascript");
        script1.Attributes.Add("src", "http://books.google.com/books/previewlib.js");
        this.Page.Header.Controls.Add(script1);

        string GoogleScript = "";

        string isbncode = "";
        if (Page.Request.QueryString["isbn"] != null)
            isbncode = Page.Request.QueryString["isbn"];

        GoogleScript = "GBS_setLanguage('en'); GBS_insertPreviewButtonPopup('ISBN:";
        isbncode = isbncode + "');";

        HtmlGenericControl script3 = new HtmlGenericControl("script");
        script3.Attributes.Add("type", "text/javascript");
        script3.InnerHtml = GoogleScript + isbncode ;
        this.Page.Controls.Add(script3);
Anuj Kulkarni
  • 2,261
  • 5
  • 32
  • 42
  • You should've injected that Javascript using RegisterClientScriptBlock as Sarwar026 suggested - much cleaner (and intended) way of doing such sort of things. – Andrey Apr 08 '12 at 18:38
0

You can easily include the ISBN as a querystring parameter in the url and pull it into your javascript code without the need for server side includes. As seen here:

function getQueryString() {
  var result = {}, queryString = location.search.substring(1),
      re = /([^&=]+)=([^&]*)/g, m;

  while (m = re.exec(queryString)) {
    result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
  }

  return result;
}

//url: www.yourwebsite.com?isbn=123456789
var _ISBN = getQueryString()["isbn"];
GBS_setLanguage('en');
GBS_insertPreviewButtonPopup(_ISBN);
Community
  • 1
  • 1
Daniel Szabo
  • 7,181
  • 6
  • 48
  • 65
  • No problem. Make sure you checkmark and upvote answers that you find helpful on stackoverflow. It helps other people find answers to their questions more quickly, and build rep for people that answer. :) – Daniel Szabo Apr 09 '12 at 18:32