#fbml=1
在<script src="http://connect.facebook.net/en_US/all.js#xfbml=1">
中做什么?(这是从http://developers.facebook.com/docs/reference/plugins/like/获得的官方Facebook Like按钮代码)
同样,在Fiddler中,我看到它只是做了一个
GET /en_US/all.js HTTP/1.1
但尝试删除#fbml=1
,页面将不显示Facebook喜欢按钮。这里的机制是什么?
标签永远不会发送到服务器,但Javascript可以通过location.hash
访问它,或者,当它在脚本标签中使用时,访问标签的src
属性。
这很可能是负责它的代码:
window.setTimeout(function () {
var a = /(connect.facebook.net|facebook.com/assets.php).*?#(.*)/;
FB.Array.forEach(document.getElementsByTagName('script'), function (d) {
if (d.src) {
var b = a.exec(d.src);
if (b) {
var c = FB.QS.decode(b[2]);
FB.Array.forEach(c, function (f, e) {
if (f == '0') c[e] = 0;
});
FB.init(c);
}
}
});
if (window.fbAsyncInit && !window.fbAsyncInit.hasRun) {
window.fbAsyncInit.hasRun = true;
fbAsyncInit();
}
}, 0);