Tag: google font api

页面加载后动态加载谷歌字体

我希望能够让用户选择他们希望页面显示的字体。 以下是Google建议您使用JavaScript执行此操作的方式。 WebFontConfig = { google: { families: [‘Tangerine’, ‘Cantarell’] } }; (function() { var wf = document.createElement(‘script’); wf.src = (‘https:’ == document.location.protocol ? ‘https’ : ‘http’) + ‘://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js’; wf.type = ‘text/javascript’; wf.async = ‘true’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(wf, s); })(); 如何修改这个以便我可以在页面加载后重新获取字体?

$ .getJSON和google fonts API在jQuery版本大于1.4.4的Internet Explorer中停止工作

我花了差不多一整天都试图找到解决这个问题的方法。 我已成功编写代码,使用Google fonts API和jQuery 1.4.4动态检索和显示大量字体。 (适用于所有浏览器) 我不得不将jQuery更改为1.7.2版,不幸的是我注意到我编写的代码在除Internet Explorer之外的所有浏览器中运行良好。 我做了一些测试,发现在使用高于1.4.4的jQuery版本时,在Internet Explorer中,$ .getJSON或$ .ajax无法从Google加载JSON字体数据。 这是我正在使用的代码: $(function(){ $.getJSON(‘https://www.googleapis.com/webfonts/v1/webfonts?key=XXXXXX’, function(json) { alert(json); }); }); 经过一些研究,我也尝试了这个: $.ajax({ type: “get”, url: “https://www.googleapis.com/webfonts/v1/webfonts?key=XXXXXXXX”, cache:false, dataType:’json’, success: function(data){ alert(data); } }); 使用任何大于1.4.4的jQuery版本,这两种方法都在Internet Explorer中失败 – 没有任何反应。 有什么想法吗? 谢谢您的帮助。