2013-03-24 36 views
1

对于Facebook粉丝页面我创建了一个静态html选项卡(https://www.facebook.com/jgsportevents/app_190322544333196),我想要使用链接的jquery插件,就像我在客户端的网站(http://tinyurl.com/c3bfz93)上所做的那样。链式插件位于标签的基本的script.js,看起来像这样:用[的script.js]在标签的index.html文件和jQueryJquery插件不工作在Facebook静态HTML选项卡

(function($) { 

$.fn.chained = function(parent_selector, options) { 

    return this.each(function() { 

     /* Save this to self because this changes when scope changes. */    
     var self = this; 
     var backup = $(self).clone(); 

     /* Handles maximum two parents now. */ 
     $(parent_selector).each(function() { 

      $(this).bind("change", function() { 
       $(self).html(backup.html()); 

       /* If multiple parents build classname like foo\bar. */ 
       var selected = ""; 
       $(parent_selector).each(function() { 
        selected += "\\" + $(":selected", this).val(); 
       }); 
       selected = selected.substr(1); 

       /* Also check for first parent without subclassing. */ 
       /* TODO: This should be dynamic and check for each parent */ 
       /*  without subclassing. */ 
       var first = $(parent_selector).first(); 
       var selected_first = $(":selected", first).val(); 

       $("option", self).each(function() { 
        /* Remove unneeded items but save the default value. */ 
        if (!$(this).hasClass(selected) && 
         !$(this).hasClass(selected_first) && $(this).val() !== "") { 
          $(this).remove(); 
        }       
       }); 

       /* If we have only the default value disable select. */ 
       if (1 == $("option", self).size() && $(self).val() === "") { 
        $(self).attr("disabled", "disabled"); 
       } else { 
        $(self).removeAttr("disabled"); 
       } 
       $(self).trigger("change"); 
      }); 

      /* Force IE to see something selected on first page load, */ 
      /* unless something is already selected */ 
      if (!$("option:selected", this).length) { 
       $("option", this).first().attr("selected", "selected"); 
      } 

      /* Force updating the children. */ 
      $(this).trigger("change");    

     }); 
    }); 
}; 

/* Alias for those who like to use more English like syntax. */ 
$.fn.chainedTo = $.fn.chained; 

})(jQuery); 

$("#bestemming").chained("#sport"); /* or $("#series").chainedTo("#mark"); *///   Javascript Document 

而且我打电话选项卡的脚本页面与http://code.jquery.com/jquery-latest.min.js'>。不幸的是,我无法让插件像我客户的网站上那样工作。

什么问题?

更新

基于法比奥安栋梁答案我已经改变了代码。不幸的是它仍然没有工作。我更改了代码,但仍然没有效果。

回答

2

你jQuery是被封锁,Facebook的块每一个来自非安全网址脚本, 所以改变这样的:

http://code.jquery.com/jquery-latest.min.js

要这样:

https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js 

一件事你字体也因为相同的原因被阻止:

http://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,400italic,700italic,400,700,300 

你只需要改变协议为HTTPS

https://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,400italic,700italic,400,700,300 

编辑

你在你的代码有一个更多的错误,你不加载Facebook的JavaScript的正确,使您的应用内触发一个javascript错误,因为这是你的应用程序将无法运行任何脚本

改变这一点:

<script> 
    FB.init({ 
    appId : 'YOUR_APP_ID', 
    status : true, // check login status 
    cookie : true, // enable cookies to allow the server to access the session 
    oauth : true // enable OAuth 2.0 
    }); 
    FB.Canvas.setAutoResize(); 
</script> 

对此:

<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
Uncaught ReferenceError: FB is not defined 
    appId : 'YOUR_APP_ID', 
    status : true, // check login status 
    cookie : true, // enable cookies to allow the server to access the session 
    oauth : true // enable OAuth 2.0 
    }); 
    FB.Canvas.setAutoResize(); 
    }; 
    // Load the SDK Asynchronously 
     (function(d){ 
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
     if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     ref.parentNode.insertBefore(js, ref); 
     }(document)); 
</script> 
+0

感谢您的回答。不幸的是它不工作。我更改了代码,但仍然没有效果。在index.html上,我打电话给script.js,其中包含以下代码:“链接插件”: – 2013-03-24 17:30:50

+0

您还有一个错误,我更新了我的答案 – 2013-03-24 18:30:03

+0

感谢您的帮助,我已经更改了它,但它仍然不工作。 – 2013-03-24 21:42:06