如果大家看到如图1那样的提示信息的话,说明你的网站名用了中文了。原来以为,asp.net 2.0应该是对中文支持得很好了,结果却是没有那么乐观。项目的名称(网站名称)如果是中文,那么fckeditor就出现了一个xml无法加载的问题:“Error loading "/fckeditor/fckstyles.xml" ”。(见图1-图3)
图1
图2
图3
例如我这个项目叫做订菜系统,那么,在VS里面运行的时候,就是http://localhost:1690/订菜系统/abc.aspx这样。
而fckeditor会在 fckeditor\editor\js\fckeditorcode_ie.js 这个脚本里面,根据浏览器地址,生成“FCKConfig.BasePath”,然后再把FCKConfig.BasePath截去一部分,生成FCKConfig.EditorPath,也就是下面这行代码:
var FCKConfig=FCK.Config={}; if (document.location.protocol=='file:') { FCKConfig.BasePath=decodeURIComponent(document.location.pathname.substr(1)); FCKConfig.BasePath=FCKConfig.BasePath.replace(/\\/gi, '/'); var sFullProtocol=document.location.href.match(/^(file\:\/{2,3})/)[1]; if (FCKBrowserInfo.IsOpera) sFullProtocol+='localhost/'; FCKConfig.BasePath=sFullProtocol+FCKConfig.BasePath.substring(0,FCKConfig.BasePath.lastIndexOf('/')+1); }else FCKConfig.BasePath=document.location.protocol+'//'+document.location.host+document.location.pathname.substring(0,document.location.pathname.lastIndexOf('/')+1); FCKConfig.FullBasePath=FCKConfig.BasePath; FCKConfig.EditorPath=FCKConfig.BasePath.replace(/editor\/$/,'');
其中倒数第一行:“FCKConfig.EditorPath=FCKConfig.BasePath.replace(/editor\/$/,'');”就是生成了“FCKConfig.EditorPath”。
在“fckconfig.js”文件里加载“fckstyles.xml”这个文件,就要使用到这个“FCKConfig.EditorPath”,代码如下:
FCKConfig.StylesXmlPath = FCKConfig.EditorPath + 'fckstyles.xml' ;
经过我在IE6下测试,不管是使用“http://localhost:1690/订菜系统/”的方式(原文);还是使用“http://localhost:1690/%e8%ae%a2%e8%8f%9c%e7%b3%bb%e7%bb%9f/”的方式(转换),都会报错。而且我在“fckconfig.js”中加了一行代码做测试:window.status = FCKConfig.EditorPath,IE状态栏始终显示的是“http://localhost:1690/订菜系统/”。
最后的解决办法是:对“FCKConfig.EditorPath”编码,即encodeURI(FCKConfig.EditorPath) 。我顺便把下面那个xml加载也加了编码,代码如下: (以下两行在fckconfig.js文件里大概160行的地方)
FCKConfig.StylesXmlPath = encodeURI(FCKConfig.EditorPath) + 'fckstyles.xml' ;
FCKConfig.TemplatesXmlPath = encodeURI(FCKConfig.EditorPath) + 'fcktemplates.xml' ;