fckeditor和谷歌浏览器不兼容的问题

原因是它读取浏览器版本时报错,最简单的改动方法就是去掉验证,即在FCKEditro.isCompatible()代码中增加判断有AppleWebKit串就 return true;
private boolean isCompatible() {
String userAgent=request.getHeader("user-agent");
if(userAgent==null)
return false;
userAgent=userAgent.toLowerCase();
if ((userAgent.indexOf("msie") !=-1) && (userAgent.indexOf("mac") == -1) && (userAgent.indexOf("opera") == -1)) {
if(retrieveBrowserVersion(userAgent)>=5.5)
return true;
}
else if (userAgent.indexOf("applewebkit") !=-1){
return true;
}
else if (userAgent.indexOf("gecko") !=-1){
if(retrieveBrowserVersion(userAgent)>=20030210)
return true;
}
return false;
}

不过这种改动不能保证后续代码与浏览器的兼容性,不如用新版.
下面的是需修改文件的源码
package com.fredck.FCKeditor;

import javax.servlet.http.HttpServletRequest;

public class FCKeditor
{
private FCKeditorConfigurations oConfig;
private String instanceName;
private String value = "";
private String basePath;
private String toolbarSet = "Default";
private String width = "100%";
private String height = "200";
HttpServletRequest request;

public String getInstanceName()
{
return this.instanceName;
}

public void setInstanceName(String value)
{
this.instanceName = value;
}

public String getValue()
{
return this.value;
}

public void setValue(String value)
{
this.value = value;
}

public String getBasePath()
{
return this.basePath;
}

public void setBasePath(String value)
{
this.basePath = value;
}

public String getToolbarSet()
{
return this.toolbarSet;
}

public void setToolbarSet(String value)
{
this.toolbarSet = value;
}

public String getWidth()
{
return this.width;
}

public void setWidth(String value)
{
this.width = value;
}

public String getHeight()
{
return this.height;
}

public void setHeight(String value)
{
this.height = value;
}

public FCKeditorConfigurations getConfig()
{
return this.oConfig;
}

public void setConfig(FCKeditorConfigurations value)
{
this.oConfig = value;
}

public FCKeditor(HttpServletRequest req)
{
this.request = req;
this.basePath = this.request.getContextPath() + "/FCKeditor/";
this.oConfig = new FCKeditorConfigurations();
}

public FCKeditor(HttpServletRequest req, String parInstanceName)
{
this.request = req;
this.basePath = this.request.getContextPath() + "/FCKeditor/";
this.instanceName = parInstanceName;
this.oConfig = new FCKeditorConfigurations();
}

public FCKeditor(HttpServletRequest req, String parInstanceName, String parWidth, String parHeight, String parToolbarSet, String parValue)
{
this.request = req;
this.basePath = this.request.getContextPath() + "/FCKeditor/";
this.instanceName = parInstanceName;
this.width = parWidth;
this.height = parHeight;
this.toolbarSet = parToolbarSet;
this.value = parValue;
this.oConfig = new FCKeditorConfigurations();
}

private boolean isCompatible()
{
String userAgent = this.request.getHeader("user-agent");
if (userAgent == null)
return false;
userAgent = userAgent.toLowerCase();
if ((userAgent.indexOf("msie") != -1) && (userAgent.indexOf("mac") == -1) && (userAgent.indexOf("opera") == -1)) {
if (retrieveBrowserVersion(userAgent) < 5.5D) break label91;
return true;
}

label91: return ((userAgent.indexOf("gecko") != -1) &&
(retrieveBrowserVersion(userAgent) >= 20030210.0D));
}

private double retrieveBrowserVersion(String userAgent)
{
if (userAgent.indexOf("msie") > -1) {
str = userAgent.substring(userAgent.indexOf("msie") + 5);
return Double.parseDouble(str.substring(0, str.indexOf(";")));
}

String str = userAgent.substring(userAgent.indexOf("gecko") + 6);
return Double.parseDouble(str.substring(0,8));
}

private String HTMLEncode(String txt)
{
txt = txt.replaceAll("&", "&");
txt = txt.replaceAll("<", "<");
txt = txt.replaceAll(">", ">");
txt = txt.replaceAll("\"", """);
txt = txt.replaceAll("'", "’");
return txt;
}

public String create()
{
StringBuffer strEditor = new StringBuffer();

strEditor.append("<div>");
String encodedValue = HTMLEncode(this.value);

if (isCompatible())
{
strEditor.append("<input type=\"hidden\" id=\"" + this.instanceName + "\" name=\"" + this.instanceName + "\" value=\"" + encodedValue + "\">");

strEditor.append(createConfigHTML());
strEditor.append(createIFrameHTML());
}
else
{
strEditor.append("<TEXTAREA name=\"" + this.instanceName + "\" rows=\"4\" cols=\"40\" style=\"WIDTH: " + this.width + "; HEIGHT: " + this.height + "\" wrap=\"virtual\">" + encodedValue + "</TEXTAREA>");
}
strEditor.append("</div>");
return strEditor.toString();
}

private String createConfigHTML() {
String configStr = this.oConfig.getUrlParams();

if (!(configStr.equals("")))
configStr = configStr.substring(1);

return "<input type=\"hidden\" id=\"" + this.instanceName + "___Config\" value=\"" + configStr + "\">";
}

private String createIFrameHTML()
{
String sLink = this.basePath + "editor/fckeditor.html?InstanceName=" + this.instanceName;

if (!(this.toolbarSet.equals("")))
sLink = sLink + "&Toolbar=" + this.toolbarSet;

return "<iframe id=\"" + this.instanceName + "___Frame\" src=\"" + sLink + "\" width=\"" + this.width + "\" height=\"" + this.height + "\" frameborder=\"no\" scrolling=\"no\"></iframe>";
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值