zoukankan      html  css  js  c++  java
  • 让Fckeditor支持中文——解决“Error loading "/fckeditor/fckstyles.xml" ”

    最近做了一个小型的项目,其中的用户部分,我大体上按照Asp时代检查cookies的方式来做的。开始的时候设想要加上SessionId和随机码,但是项目一开始运做,就发现工作量实在太大了。用户安全这个地方,只好暂时放一放。

    但是昨天(实际上的问题是周六下午遇到的)一整天都让不支持中文的问题给绊住了。原来以为,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.StylesXmlPath  = encodeURI(FCKConfig.EditorPath) + 'fckstyles.xml' ;
    FCKConfig.TemplatesXmlPath
    = encodeURI(FCKConfig.EditorPath) + 'fcktemplates.xml' ;


    目前为止,问题算是解决了。如果其它的地方还有类似的错误,也可以直接修改这里:“FCKConfig.EditorPath=FCKConfig.BasePath.replace(/editor\/$/,'');”

    另一个问题,就是asp.net 2.0 中cookies的名称使用中文的问题。这个问题暂时还没有找到比较好的解决办法。

    具体现象就是,在IIS6中“站点名称_admin”这个的cookies,如果页面url包含?后面的querystring。那么cookies就找不到了。

    刚才,在网上找到一篇文章:《ASP.net:cookies的丢失和中文乱码》(http://www.ninedns.com/asp.net/2007102520654.html),里面用了“HttpUtility.UrlEncode”和“HttpUtility.UrlDecode”来分别编码和反编码cookies的名称。但是我原来觉得这并不是最完美的解决方案,至少,为什么会乱码,根源没有找到。我感觉可能和asp.net保存用户状态的机制有关。后来在页面上打开Trace,这才看到,windows 20003 IIS6上cookies的中文内容是乱码的。而在vs 2005上面就没有乱码!

    看来这篇文章的解决办法还真是“唯一的办法”了。

  • 相关阅读:
    将包含<pre>标签的json转换成js
    JS 获取系统时间
    JS 对url进行编码
    DevExpress.XtraCharts.ChartControl 实例
    VB 窗体继承
    datagrid 属性
    SQLite操作总结
    Struts2 简介及学习方法介绍
    struts2 中使用DMI(动态调用方法)方式配置action
    JSP 里 的 basePath
  • 原文地址:https://www.cnblogs.com/xpnew/p/fckeditorLoadXMLError.html
Copyright © 2011-2022 走看看