简体   繁体   English

JQuery load() 将像按钮/评论框一样破坏 facebook。 如何解决?

[英]JQuery load() will break facebook like button/comment box. How to workaround?

I am coding a big website but I have cut down my problem into the following tiny html file:我正在编写一个大网站,但我已将我的问题缩减为以下微小的 html 文件:

http://dl.dropbox.com/u/3224566/test.html http://dl.dropbox.com/u/3224566/test.html

The problem is that if I (re)load with JQuery a content that features a facebook code, the latter won't appear, even if I reload the script (leading to a duplication of that all.js script, which is another issue).问题是,如果我(重新)使用 JQuery 加载具有 facebook 代码的内容,即使我重新加载脚本,后者也不会出现(导致复制 all.js 脚本,这是另一个问题) .

How can I fix this?我怎样才能解决这个问题?

Regards, Quentin问候,昆汀

Use the FB.XFBML.parse() docs after you load the new content加载新内容后使用FB.XFBML.parse()文档

function loadPage() {
  $('#test').load('test.html #test', function() {
    FB.XFBML.parse( );
  }).fadeOut('slow').fadeIn('slow');
}

Note, that loading a fragment with id test in a div with id test will create multiple ( two ) elements with the same id ( nested in each other ) in the page, which should never happen as it is invalid.请注意,在具有 id test的 div 中加载具有 id test的片段将在页面中创建多个(两个)具有相同 id(彼此嵌套)的元素,这永远不会发生,因为它是无效的。

To avoid this use the more verbose $.get method为避免这种情况,请使用更详细的$.get方法

$.get('test.html', 
        function(data) {
                    var temp = $('<div>').html(data).find('#test');
                    $('#test').html(temp.html());
              }
      );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM