2012-07-28 34 views
19

直到用戶點擊網站的SSL部分,我的網站才能與Google網頁字體兼容。Google網頁字體和SSL錯誤

在這一點上,鉻會拋出部分編碼錯誤,而我的cufon菜單損失它的kerning。

我包括我的web字體與此CSS:

@font-face { 
src: local('Lusitana'), url(https://themes.googleusercontent.com/static/fonts/lusitana 
/v1/tAIvAkRzqMJf8Y4fM1R7PXYhjbSpvc47ee6xR_80Hnw.woff) format('woff'); 
} 

然後我的JS控制檯給我這個錯誤:

[blocked] The page at https://domain.com/ecommerce.php ran insecure content from http://fonts.googleapis.com/css?family=Lusitana:regular,700&subset=latin .

任何想法如何,我可以得到谷歌的字體強制SSL?

+1

我也遇到過這個問題。我已經測試過鏈接href =「// fonts.googleapis.com/css?family=Gudea」rel =「stylesheet」type =「text/css」and link href =「https://fonts.googleapis.com/ css?family = Gudea「rel =」stylesheet「type =」text/css「但問題是一樣的 – 2012-08-14 11:30:33

回答

76

您是否試圖在//中更換https://?該請求應自動使用正確的協議。

+6

簡單而有效。很好的答案,值得接受。 – Chris 2013-06-21 17:15:03

+0

似乎不再支持通過HTTP加載字體,即使整個網站僅HTTP,我也只能通過Chrome在HTTPS上加載字體。 – 2016-01-12 16:55:21

+0

同時檢查服務器是否可能返回任何緩存失效報頭; IExplorer不能很好地處理它,並且不會顯示字體:[see here](http://stackoverflow.com/a/43094126/1767316) – user1767316 2017-03-29 12:59:26

3

要加載可在非安全模式和SSL模式下工作的Google字體,請在頁面標題中嘗試以下操作(並刪除您在CSS中調用https://的內容):

<script type="text/javascript"> 
    WebFontConfig = { google: { families: [ 'Droid+Serif::latin' ] } }; 
    (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); 
})(); 
</script> 

在我的示例中,我使用Droid Serif字體,因此請將其與您的交換。

You can read more on this here.

+1

請參閱下面的@ londonium的答案,以獲得一個更簡單的解決方案,它的工作原理和有效性。 – Chris 2013-06-21 17:14:32

4

找到你的HTML頁面(或模板)在這條線:

<link href='http://fonts.googleapis.com/css?family=Dosis:400,700' rel='stylesheet' type='text/css'> 

它改成這樣:

<link href='//fonts.googleapis.com/css?family=Dosis:400,700' rel='stylesheet' type='text/css'> 

這個簡單的變化會讓你的瀏覽器調用Google字體頁面處於適用模式(HTTP vs HTTPS)。

享受!

+0

我無法在chrome v49(非https本地頁面)中使用// ..但https正常工作。 Google建議在所有這些通話中使用https,並且可能最好堅持使用https:// – Ross 2016-04-20 23:53:07

+0

這些聲明的任何引用? – TonyG 2017-04-20 19:50:41