Updating Facebook like URL in jQuery
I have the following script. As you can see it does update the fb href but for some strange reason the like fails to process. Have I messed something?
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>
<script>
$(document).ready(function() {
$('#submit').click(function() {
$('fb\\:like').attr('href', $("#URL"开发者_C百科).val());
});
});
</script>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=174802005910704&xfbml=1"></script>
<fb:like href="#" send="false" layout="box_count" width="80" show_faces="false" font=""></fb:like>
<input type="text" id="URL" />
<input type="button" id="submit" value="go">
</body>
</html>
Any help would be greatly appreciated.
No this will not do much because the <fb:like>
tag has already been processed and rendered. all you are doing (if it actually works) is changing the attribute, which has no effect whatsoever
Try to explain what you are trying to accomplish and you will get a better answer
Add this to your html
<div class="share"></div>
On load and when a button is pressed or some state is changed call this function
function update_share_location() {
// Empty previous share stuff
$('.share').empty();
// Your new share location
var url_loc = 'http://yournewshare.com';
share_options = '<iframe src="//www.facebook.com/plugins/like.php?href='+url_loc+'&send=false&layout=button_count&width=250&show_faces=false&action=like&colorscheme=light&font&height=26" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:26px;" allowTransparency="true"></iframe>';
// Update html
$('.share').html(share_options);
}
精彩评论