2007-2-12 08:07 PM
fsb800
嘗試分析使用Firefox顯示主頁出現亂碼
3talks 主頁用firefox 顯示亂碼 相信不是近來的事 (用IE 正常顯示)
近日有版友提及這事 大家都好像習以為常
不過於網頁顯示上 firefox向來遵從規格 而IE卻往往有"自己的一套規格"
[color=red]Encoding 為網頁顯示其中一項最重要的部份 firefox怎麼可能會容許有這樣的大問題?[/color]
剛剛興之所至 嘗試找出原因 以下為我的發現 希望能幫助解決亂碼問題
主頁: [url=http://www.3talks.com]http://www.3talks.com[/url]
就像圖中顯示一樣.. 網頁上下其餘部份 全部正常
[attach]198616[/attach]
3talks 使用 UTF-8... 先看主頁的 html source code 節錄 head 部份
[indent][b][code]<meta http-equiv="Content-Type" content="text/html; charset=utf-8">[/code][/b][/indent]
文件 utf-8 設定正常 為何還是顯示亂碼? 追蹤出現亂碼部份 其實為一個 iframe.. source 為 [url=http://www.3talks.com/indexnews.html]http://www.3talks.com/indexnews.html[/url]
解構 indexnews.html 出現亂碼的地方 主要可分為兩部份
而左上角出現的 [b]嚜�[/b] 亦是很常見 UTF-8 內容未能正常顯示的症狀
[attach]198617[/attach]
[list=1][*][size=4][color=blue]indexnews.html 的 html code[/color][/size]
[attach]198618[/attach]
看看 html source code 節錄 head 部份
[indent][b][code]<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />[/code][/b][/indent]
文件 utf-8 設定正常
[*][size=4][color=blue]indexnews.html 從 server get回來的 inline javascript code[/color][/size]
[attach]198619[/attach]
從 <script> 指定 [i]http://www.3talks.com/api/javascript.php[/i] 所獲取的最新資料
由於是 inline code 所以不需額外文件 charset 設定[/list]
[color=red]按照上述兩項 文件已設定為 utf-8 那為何不能顯示正常?[/color]
其實現在假如你把 firefox的 encoding手動設置為 UTF-8 就已經可以把 html code部份的亂碼 顯示正常了
意思就是 firefox收到 indexnews.html後 並沒有以 UTF-8來顯示 所以出現亂碼
那既然已設定 UTF-8 是否 firefox設定問題?
我們先再看深入一點 檢查各文件的 HTTP header
[list][*][size=4][color=green]indexnews.html 部份 header[/color][/size]
[b]Content-Type: text/html; charset=Big5[/b][*][size=4][color=green]javascript.php 部份 header[/color][/size]
[b]Content-Type: text/html; charset=Big5[/b][/list]
我們再回頭看看 3talks 主頁的 HTTP header
[list][*][size=4][color=green]3talks 主頁 部份 header[/color][/size]
[b]Content-Type: text/html; charset=utf-8[/b][/list]
[u][size=4]終於看到問題的所在了 原來 indexnews.html 及 javascript.php 所送出的內容 並未有指示為 UTF-8[/size][/u]
結果 firefox嘗試使用 Big5 就把 UTF-8 的內容顯示成亂碼了
那 IE正常顯示... 又如何解釋?
參考一篇 W3 有關 charset 的文章: [url=http://www.w3.org/International/O-charset]http://www.w3.org/International/O-charset[/url]
[indent][b]Ensure that there is no conflict between what you declare in the document and what the server automatically applies, since server settings override in-document declarations.[/b]
簡單意思是說 server所指示的 encoding設定 會覆蓋文件中所使用的 encoding設定[/indent]
換句話講 firefox遵從了 w3的規格 而使用了 Big5
IE 卻原來暗地裡 "擅自" 優先考慮文件 encoding設定 而使用了 UTF-8
時間關係暫只分析原因 恕未能補上可能的解決辦法(有時間會嘗試貼上解決方法) 歡迎高手加入補充 :handshake
[[i] 本帖最後由 fsb800 於 2007-2-12 08:29 PM 編輯 [/i]]
2007-2-12 08:45 PM
㊣修羅-黑暗㊣
呢個論壇九成人既電腦程度,都唔會明白,唔會解決到
2007-2-13 01:26 AM
fsb800
同意樓上修羅兄之言
這種問題 要由會員自己修正 實在有困難
所以最好就是論壇解決問題本身 以下為小弟提議可能有效的辦法
[list=1][*][size=4][color=blue]使用 .htaccess[/color][/size]
在與.html文件相同的資料夾中建立檔名為 .htaccess,內容為
[indent][b]AddCharset UTF-8 .html .htm[/b][/indent]
W3 有關使用 .htaccess 設定 charset 的文章: [url=http://www.w3.org/International/questions/qa-htaccess-charset]http://www.w3.org/International/questions/qa-htaccess-charset[/url]
[*][size=4][color=blue]更改 server設定及內容的產生[/color][/size]
[list=a][*][size=4][color=green]server 設定[/color][/size]
從 server設定送出去的內容 都是利用適當的 charset
3talks 使用 apache 節錄一段 W3 文章: [url=http://www.w3.org/International/O-HTTP-charset]http://www.w3.org/International/O-HTTP-charset[/url]
[indent]This can be done via the [url=http://httpd.apache.org/docs/mod/mod_mime.html#addcharset]AddCharset[/url] (Apache 1.3.10 and later) or [url=http://httpd.apache.org/docs/mod/mod_mime.html#addtype]AddType[/url] directives, for directories or individual resources (files). With [url=http://httpd.apache.org/docs-2.0/mod/core.html#adddefaultcharset]AddDefaultCharset[/url] (Apache 1.3.12 and later), it is possible to set the default 'charset' for a whole server. For more information, see the article on [url=http://www.w3.org/International/questions/qa-htaccess-charset]Setting 'charset' information in .htaccess[/url].[/indent]
[*][size=4][color=green]利用 script編寫 header[/color][/size]
好像使用 Discuz!的 JS調用 網頁內容由 script產生
script同時亦可以產生 header 資料
節錄上面同一篇 W3 文章:
[indent][b]PHP[/b]. Use the header() function before generating any content, e.g.:
[b]header('Content-type: text/html; charset=utf-8');[/b][/indent][/list][/list]
希望以上方法對管理人員有參考價值
如有更多資料 再加以補充 :loveliness:
[[i] 本帖最後由 fsb800 於 2007-2-13 01:32 AM 編輯 [/i]]
2007-2-13 03:10 AM
東風
[quote]原帖由 [i]fsb800[/i] 於 2007-2-13 01:26 AM 發表
同意樓上修羅兄之言
這種問題 要由會員自己修正 實在有困難
所以最好就是論壇解決問題本身 以下為小弟提議可能有效的辦法
使用 .htaccess
在與.html文件相同的資料夾中建立檔名為 .htaccess,內容為
AddCharset UTF ... [/quote]
多謝你d咁正資料, 我會嘗試解決亂碼問題!
2007-2-13 03:14 AM
域奇
[quote]原帖由 [i]fsb800[/i] 於 2007-2-12 08:07 PM 發表
3talks 主頁用firefox 顯示亂碼 相信不是近來的事 (用IE 正常顯示)
近日有版友提及這事 大家都好像習以為常
不過於網頁顯示上 firefox向來遵從規格 而IE卻往往有"自己的一套規格"
Encoding 為網頁顯示其中 ... [/quote]
果然高手、高手、高高手。:boy11:
我用firefox都集以為常囉。;P
2007-2-13 03:14 AM
fsb800
[quote]原帖由 [i]東風[/i] 於 2007-2-13 03:10 發表
多謝你d咁正資料, 我會嘗試解決亂碼問題! [/quote]
加油 :boy09: :boy11:
有需要幫忙 即管講聲 :msn16:
勁 :msn06: :msn06: 搞店左js果度la :msn16:
(甘岩見到一堆廣告帖 :funk:)
假如成功解決後 東風兄可否告之最後用何方法 :msn03:
最新.. 已完全ko! 東風兄好野 :boy11:
[[i] 本帖最後由 fsb800 於 2007-2-13 03:25 AM 編輯 [/i]]
2007-2-13 03:25 AM
fsb800
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 03:14 發表
果然高手、高手、高高手。:boy11:
我用firefox都集以為常囉。;P [/quote]
東風連夜趕工 修正好la :boy11::boy11: :msn06:
2007-2-13 03:33 AM
域奇
[quote]原帖由 [i]fsb800[/i] 於 2007-2-13 03:14 AM 發表
加油 :boy09: :boy11:
有需要幫忙 即管講聲 :msn16:
勁 :msn06: :msn06: 搞店左js果度la :msn16:
(甘岩見到一堆廣告帖 :funk:)
假如成功解決後 東風兄可否告之最後用何方法 :msn03:
最新.. 已完全ko! 東風兄 ... [/quote]
但係,點解我仲有啲亂碼嘅?
順帶一提,批量删除好好用。;P
2007-2-13 03:34 AM
fsb800
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 03:33 發表
但係,點解我仲有啲亂碼嘅?
順帶一提,批量删除好好用。;P [/quote]
再reload la ;P;P
2007-2-13 03:49 AM
域奇
[quote]原帖由 [i]fsb800[/i] 於 2007-2-13 03:34 AM 發表
再reload la ;P;P [/quote]
reload咗十幾次喇!:L
2007-2-13 03:58 AM
fsb800
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 03:49 發表
reload咗十幾次喇!:L [/quote]
就甘按 CTRL+R 都吾店 :msn03::msn03:
03:53 截圖
[size=5]IE 6[/size]
[attach]199144[/attach]
[size=5]Firefox 2[/size]
[attach]199145[/attach]
[[i] 本帖最後由 fsb800 於 2007-2-13 03:59 AM 編輯 [/i]]
2007-2-13 04:07 AM
域奇
[quote]原帖由 [i]fsb800[/i] 於 2007-2-13 03:58 AM 發表
就甘按 CTRL+R 都吾店 :msn03::msn03:
03:53 截圖
IE 6
199144
Firefox 2
199145 [/quote]
真係唔得!唔知高手可以點幫我呢?:funk:
2007-2-13 04:10 AM
fsb800
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 04:07 發表
真係唔得!唔知高手可以點幫我呢?:funk: [/quote]
雖然應該吾關事 你即管試下甘la [img]http://www.3talks.com/images/smilies/msn10.gif[/img]
2007-2-13 04:21 AM
域奇
[quote]原帖由 [i]fsb800[/i] 於 2007-2-13 04:10 AM 發表
雖然應該吾關事 你即管試下甘la [img]http://www.3talks.com/images/smilies/msn10.gif[/img] [/quote]
死症!:L
2007-2-13 07:48 AM
vwfl
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 04:21 AM 發表
死症! [/quote]
用上面Clear Now嗰時,試吓清埋cookies,咁樣:
2007-2-13 12:04 PM
㊣修羅-黑暗㊣
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 04:21 AM 發表
死症!:L [/quote]
又係你
次次都人得你唔得~~;P
2007-2-13 12:21 PM
域奇
[quote]原帖由 [i]㊣修羅-黑暗㊣[/i] 於 2007-2-13 12:04 PM 發表
又係你
次次都人得你唔得~~;P [/quote]
重新開機又得了。:victory::victory::victory:
2007-2-13 12:24 PM
fsb800
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 12:21 發表
重新開機又得了。:victory::victory::victory: [/quote]
都話ga la ;P
2007-2-14 11:08 AM
㊣修羅-黑暗㊣
[quote]原帖由 [i]域奇[/i] 於 2007-2-13 12:21 PM 發表
重新開機又得了。:victory::victory::victory: [/quote]
原來又係你做野屙D瀨D~~;P
2007-2-14 05:47 PM
域奇
唉~好得一日,今日又嚟!:L
頁:
[1]
2
Powered by Discuz! Archiver 5.5.0
© 2001-2006 Comsenz Inc.