Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add a Facebook "Like" button to an AJAX driven page
    primarykey
    data
    text
    <p>I have trawled the net and Stack Overflow and have not found an adequate answer to this question. Before I start the trial and error process of finding my own solution, I thought I would turn to the Stack Overflow braintrust and see if there was already a successful implementation.</p> <p>I have an AJAX powered page that degrades properly for non-javascript browsers and SEO. Each click in the AJAX version can be represented by a unique URL. </p> <p>What I want to do is to dynamically change the HREF of the button. I do understand that this tag is converted to standard HTML at runtime (namely into a nasty table / iframe layout).</p> <p>I was just wondering if anyone had any insight as to how to implement this FB like button onto AJAX powered pages?</p> <p>Cheers in advance :)</p> <p><strong>EDIT:</strong></p> <p>What do you think of this method I just hacked together? See any huge problems with it?</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="JS/jquery/jquery.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="http://connect.facebook.net/en_US/all.js#xfbml=1"&gt;&lt;/script&gt; &lt;script language="javascript" type="text/javascript"&gt; $("document").ready ( function () { CreateNewLikeButton("http://www.yahoo.com") $("a#ChangeToGoogle").click ( function (e) { e.preventDefault(); CreateNewLikeButton("http://www.google.ca") } ); } ); function CreateNewLikeButton(url) { var elem = $(document.createElement("fb:like")); elem.attr("href", url); $("div#Container").empty().append(elem); FB.XFBML.parse($("div#Container").get(0)); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;a id="ChangeToGoogle" href="#"&gt;Change To Google&lt;/a&gt; &lt;div id="Container"&gt; &lt;fb:like href="http://www.NEVER_LINK_TO_THIS_12345.com"&gt;&lt;/fb:like&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload