fckeditor和谷歌浏览器不兼容的问题
来源:互联网 发布:怎样在淘宝卖二手货 编辑:程序博客网 时间:2024/06/01 10:51
原因是它读取浏览器版本时报错,最简单的改动方法就是去掉验证,即在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>";
}
}
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>";
}
}
- fckeditor和谷歌浏览器不兼容的问题
- rails 和fckeditor不兼容的解决办法
- jplayer不兼容IE浏览器的问题
- 工作总结,关于浏览器不兼容的问题。
- top.location.href 不兼容 火狐和谷歌浏览器。。
- top.location.href 不兼容 火狐和谷歌浏览器。。
- 浏览器的不兼容
- window.history.go(-1);window.history.back(); 在谷歌浏览器不兼容的问题
- &.nbsp;在IE和谷歌浏览器中不兼容的解决办法
- JSF1.2页面跳转时,IE和Chrome,FireFox浏览器不兼容的一个小问题
- WEB前端浏览器不兼容导致的问题及解决方案
- IE浏览器不兼容<a href=##>问题的解决
- WEB前端浏览器不兼容导致的问题及解决方案
- WEB前端浏览器不兼容导致的问题及解决方案
- 轻松解决Win7与IE8浏览器不兼容的问题
- google Chrome不 兼容FCKeditor
- eWebEditor不兼容IE8等浏览器问题
- FCKEDITOR与谷歌浏览器上传图片特别奇怪问题
- 旅游自助系统可行性分析
- 字节对齐、sizeof的问题分析
- POJ-2002,3432(搜点,hash或二分)
- http://acm.nyist.net/JudgeOnline/problem.php?pid=257&&中缀表达式变后缀表达式
- 华天正的开发板 如何单独编译kernel
- fckeditor和谷歌浏览器不兼容的问题
- do...while(0)的妙用
- GTK 程序 检测 网线是否连接 本地网络状态 C语言实现
- python学习---2 (rpyc)
- adb shell input 命令
- 用java –jar 命令运行Jar包 Shawn Silverman
- ajax php 跨域处理
- 关于死锁产生的原因以及解决的办法
- Java 基础(三) 继承 多态 -------面向对象的特殊性能