2013-01-24 37 views
0

我不知道为什么,虽然得到类似的问题。Webfont加载程序和Google JSAPI无法加载在一起?

尝试从fonts.com加载字体与webfontloader所以我可以调用它们加载后的函数。

<script src="https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script> 
<script> 
    WebFont.load({ 
     monotype: { 
     projectId: 'xxxxxxxxxxxxxxxxxxxx' 
     }, 
     active: function() { 
     mainNav(); 
     } 
    }); 

但是当过我包括它的JSAPI

<script src="https://www.google.com/jsapi"></script> 

我在控制台中的以下问题: 遗漏的类型错误:无法调用空

的方法 'hasAttribute'

然而,如果单独加载,他们很好...

任何想法?

回答

2

尝试使用以下URL来加载网络字体API:

<script src="//ajax.googleapis.com/ajax/libs/webfont/1.1.2/webfont.js"></script> 

检查以下职位的详细信息:https://groups.google.com/forum/#!msg/google-ajax-search-api/dWVzQF_YWCM/Y3-R738wh78J

We no longer support partial version aliases for new versions of libraries. Any partial version aliases already in place will continue to be supported and updated. The reason is that URLs like https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js which is saying "give me the most recent version of jquery 1.x.x) have very short cache lifetimes since the most recent version can change at any time. This is bad for performance. This is also bad for your web site, in the event that a library makes breaking changes in its APIs between versions that cause your page to suddenly render differently. Libraries do not usually make such changes intentionally but pages sometimes depend on behavior of an unspecified corner case of an API that may be changed intentionally or inadvertently as the library is updated.

So we strongly recommend that you specify the complete version string when referencing libraries hosted on the Google AJAX APIs. You can always find the most recent version at https://developers.google.com/speed/libraries/devguide . In this case, the most recent 1.9.x version is currently 1.9.1 so we suggest using the URL https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js to get a stable version and better caching.

(另外,你上面的例子没有关闭</script>标签。只是想验证这不存在于您自己的代码中)。

相关问题