IE / Mozilla WYSIWYG编辑器 - IE和queryCommandEnabled的问题 [英] IE/Mozilla WYSIWYG editor - problems with IE and queryCommandEnabled

查看:48
本文介绍了IE / Mozilla WYSIWYG编辑器 - IE和queryCommandEnabled的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个WYSIWYG

编辑器上的Internet Explorer和javascript问题。这一切都在Mozilla中运行,但IE返回

queryCommandEnabled(''forecol'')。 JS不是我的强项,所以我转向你所有专家的帮助。我在这里错过了什么?其他命令如

formatblock,fontsize和fontname都可以正常工作,所以我认为它因为
$而没有得到正确的选择而与
有关。 b $ b iframe。非常感谢任何帮助。


在HTML文档中,我有以下行:


< img src =" images / forecol .PNG" onClick =" DoTextFormat(''forecolor'','''')"

id =" forecolor">

< iframe width =" 175 QUOT;高度= QUOT; 125" ID = QUOT; forecolor0" src =" palette.html"

style =" visibility:hidden;位置:绝对;左:0px;顶部:

0px;">< / iframe>


palette.html是这样的:

< html>

< head>

< title> Color Palete< / title>

< script language =" JavaScript" type =" text / javascript">

<! -

函数selectColor(color){

self.parent.setColor (颜色);

}

函数InitColorPalette(){

if(document.getElementsByTagName)

var x = document.getElementsByTagName(''TD'');

else if(document.all)

var x = document.all.tags(''TD'') ;

for(var i = 0; i< x.length; i ++){

x [i] .onclick = click;

}

}

函数click(){

str = this.id;

color = str.replace( ''c'',''#'');

selectColor(颜色);

}

- >

< / script>

< style type =" text / css">

<! -

html,body {margin:0px; padding:0px;}

td {border:black none 2px;}

td:hover {border:white solid 2px;}

- - >

< / style>

< meta http-equiv =" Content-Type"含量=" text / html的; charset = ISO-8859-1">

< / head>


< body bgcolor =" white" onLoad =" InitColorPalette()">

< table border =" 0" CELLPADDING = QUOT; 0" cellspacing =" 2"

< tr>

< td id =" cFFFFFF" BGCOLOR = QUOT;#FFFFFF"宽度= QUOT; 15" height =" 15"& nbsp;< / td>

< td id =" cFFCCCC" BGCOLOR = QUOT;#FFCCCC"宽度= QUOT; 15" height =" 15"& nbsp;< / td>

....


在包含的javascript源文件中,我有以下功能:


函数DoTextFormat(命令,选项){

if((command ==''forecolor'')||(command ==' 'hilitecolor'')){

parent.command = command;

layerid = command +''0'';

buttonElement = document。 getElementById(command);


document.getElementById(layerid).style.left = getOff setLeft(buttonElement)

+''px'';


document.getElementById(layerid).style.top =(getOff setTop(buttonElement)

+ buttonElement.offsetHeight)+''px'';

if(document.getElementById(layerid).style.visibili ty ==''hidden'')

document.getElementById(layerid).style.visibility =''visible'' ;

else {

document.getElementById(layerid).style.visibility =''hidden'';

}


//获取当前所选范围

var

sel = document.getElementById(''iView'')。contentWindow .document.selection;

if(sel!= null){

rng = sel.createRange();

}

} else {


if(document.getElementById(''iView'')。contentWindow。 document.queryCommandEnabled(command)){


document.getElementById(''iView'')。contentWindow.doc ument.execCommand(command,

false,选项);

返回true;

}否则返回false;

}

document.getElementById('' iView'')。contentWindow.foc us();

}


函数setColor(color){

elem = command + ''0';

if(browser.isIE5up){

//检索所选范围

var

sel = document.getElementById(''iView'')。contentWindow .document.selection;

if(sel!= null){

var newselectionRange = sel.createRange ();

newselectionRange.select();

}

} else {

document.getElementById(' 'iView'')。contentWindow.foc us();

}


if(document.getElementById(''iView'')。contentWindow。document .queryCommandEnabled(command)){


document.getElementById(' 'iView'')。contentWindow.doc ument.execCommand(命令,

false,颜色);

}否则{


alert(" queryCommandEnabled(" + command +")返回false。无法设置颜色

到+颜色;

//退出功能前关闭调色板

document.getElementById(elem).style。 visibility =''hi dden'';

返回false;

}

document.getElementById(''iView'')。contentWindow。 foc us();

document.getElementById(elem).style.visibility =''hi dden'';

返回true;

}


TIA


-

Justin Koivisto - sp ** @ koivi.com

PHP海报:请使用comp.lang.php获取与PHP相关的问题,

alt.php *不推荐团体。

I am having a problem with Internet Explorer and javascript on a WYSIWYG
editor I am creating. It all works in Mozilla, but IE returns flase for
queryCommandEnabled(''forecol''). JS isn''t my strong suit, so I am turning
to all you experts for help. What am I missing here? Other commands like
formatblock, fontsize and fontname all work fine, so I assume that it
has something to do with not getting the correct selection because of
the iframe. Any help is greatly appreciated.

In an HTML document I have the following line:

<img src="images/forecol.png" onClick="DoTextFormat(''forecolor'','''')"
id="forecolor">
<iframe width="175" height="125" id="forecolor0" src="palette.html"
style="visibility: hidden; position: absolute; left: 0px; top:
0px;"></iframe>

palette.html is like this:
<html>
<head>
<title>Color Palete</title>
<script language="JavaScript" type="text/javascript">
<!--
function selectColor(color){
self.parent.setColor(color);
}
function InitColorPalette(){
if (document.getElementsByTagName)
var x = document.getElementsByTagName(''TD'');
else if (document.all)
var x = document.all.tags(''TD'');
for (var i=0;i<x.length;i++){
x[i].onclick = click;
}
}
function click(){
str=this.id;
color=str.replace(''c'',''#'');
selectColor(color);
}
-->
</script>
<style type="text/css">
<!--
html,body{margin: 0px; padding: 0px;}
td{border: black none 2px;}
td:hover{border: white solid 2px;}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>

<body bgcolor="white" onLoad="InitColorPalette()">
<table border="0" cellpadding="0" cellspacing="2">
<tr>
<td id="cFFFFFF" bgcolor="#FFFFFF" width="15" height="15">&nbsp;</td>
<td id="cFFCCCC" bgcolor="#FFCCCC" width="15" height="15">&nbsp;</td>
....

In the included javascript source file I have the following functions:

function DoTextFormat(command, option){
if((command==''forecolor'') || (command==''hilitecolor'')){
parent.command=command;
layerid=command+''0'';
buttonElement=document.getElementById(command);

document.getElementById(layerid).style.left=getOff setLeft(buttonElement)
+ ''px'';

document.getElementById(layerid).style.top=(getOff setTop(buttonElement)
+ buttonElement.offsetHeight) + ''px'';
if(document.getElementById(layerid).style.visibili ty==''hidden'')
document.getElementById(layerid).style.visibility= ''visible'';
else{
document.getElementById(layerid).style.visibility= ''hidden'';
}

//get current selected range
var
sel=document.getElementById(''iView'').contentWindow .document.selection;
if(sel!=null){
rng=sel.createRange();
}
}else{

if(document.getElementById(''iView'').contentWindow. document.queryCommandEnabled(command)){

document.getElementById(''iView'').contentWindow.doc ument.execCommand(command,
false, option);
return true;
}else return false;
}
document.getElementById(''iView'').contentWindow.foc us();
}

function setColor(color){
elem=command+''0'';
if(browser.isIE5up){
//retrieve selected range
var
sel=document.getElementById(''iView'').contentWindow .document.selection;
if(sel!=null){
var newselectionRange=sel.createRange();
newselectionRange.select();
}
}else{
document.getElementById(''iView'').contentWindow.foc us();
}

if(document.getElementById(''iView'').contentWindow. document.queryCommandEnabled(command)){

document.getElementById(''iView'').contentWindow.doc ument.execCommand(command,
false, color);
}else{

alert("queryCommandEnabled("+command+") returned false. Cannot set color
to "+color);
// close palette before exiting function
document.getElementById(elem).style.visibility=''hi dden'';
return false;
}
document.getElementById(''iView'').contentWindow.foc us();
document.getElementById(elem).style.visibility=''hi dden'';
return true;
}

TIA

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

推荐答案

我不确定您的确切问题是什么,但您可能希望合并

一些这类逻辑可以防止模糊的浏览器版本和

变种,Mac等等的错误...:好的客户端脚本永远不应该

引用兄弟wser的名字。


< html>

< head>

< script language =" javascript"> ;

功能测试(){

if(frames.length&&帧[''iView'']&& frames [''iView'']。document&&

frames [''iView'']。document.queryCommandEnabled){

alert(frames ['' iView'']。document.queryCommandEnabled(" forecolor"))

}

else

if(document.getElementById&&

document.getElementById(''iView'')。contentWindow&&

document.getElementById(''iView'')。contentWindow.que ryCommandEnabled)


alert(document.getElementById(''iView'')。contentWind ow.document.queryCommandEn

abled(" forecolor"))

else

alert(浏览器无法处理脚本编辑!)

}

onload = test;

< / script>

< / head>

< body>

< iframe id =" iView" ;名称= QUOT;&的iView QUOT; src =" test.html">< / iframe>

< / body>

< / html>


I''m not sure what your exact problem is, but you might wish to incorporate
some of this type of logic to prevent errors on obscure browser versions and
variations, Macs and the like...: Good client-side script should never
reference a browser by name.

<html>
<head>
<script language="javascript">
function test() {
if (frames.length && frames[''iView''] && frames[''iView''].document &&
frames[''iView''].document.queryCommandEnabled) {
alert(frames[''iView''].document.queryCommandEnabled("forecolor"))
}
else
if (document.getElementById &&
document.getElementById(''iView'').contentWindow &&
document.getElementById(''iView'').contentWindow.que ryCommandEnabled)

alert(document.getElementById(''iView'').contentWind ow.document.queryCommandEn
abled("forecolor"))
else
alert("Browser cannot handle scripted editing!")
}
onload = test;
</script>
</head>
<body>
<iframe id="iView" name="iView" src="test.html"></iframe>
</body>
</html>



" Nobody" <无** @ nope.net>写道:
"Nobody" <no**@nope.net> writes:
好的客户端脚本不应该按名称引用浏览器。
Good client-side script should never reference a browser by name.




我必须不同意在那个。


虽然我主张写标准,但有些页面还必须支持基于标准的方法不能工作的浏览器。 />
(通常是NS4或IE4)。


对于这些页面,我更喜欢专门检测浏览器并为它制作

例外。没有绝对安全的方法来检测

浏览器(一些谎言),但检查名称比

许多其他检查要好。


/ L

-

Lasse Reichstein Nielsen - lr * @ hotpop .com

Art D''HTML:< URL:http://www.infimum.dk/HTML/randomArtSplit.html>

''没有判断的信仰只会降低神灵的精神。''



I''ll have to disagree on that.

While I advocate writing to the standards, some pages also have to
support browsers where the standards based methods won''t work
(typically NS4 or IE4).

For such pages, I prefer detecting the browser specifically and make
exceptions for it. There is no absolutely safe method of detecting the
browser (some of the lie), but checking for the name is better than
many other checks.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D''HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
''Faith without judgement merely degrades the spirit divine.''




" Lasse Reichstein Nielsen" < lr*@hotpop.com>在留言中写道

新闻:k7 ********** @ hotpop.com ...

| "没有人" <无** @ nope.net>写道:

|

| >好的客户端脚本不应该按名称引用浏览器。

|

|我不得不对此不以为然。

|

|虽然我主张写标准,但有些页面也必须

|支持基于标准的方法不起作用的浏览器

| (通常是NS4或IE4)。


NS4非常简单。 document.layers


IE

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:k7**********@hotpop.com...
| "Nobody" <no**@nope.net> writes:
|
| > Good client-side script should never reference a browser by name.
|
| I''ll have to disagree on that.
|
| While I advocate writing to the standards, some pages also have to
| support browsers where the standards based methods won''t work
| (typically NS4 or IE4).

NS4 is very easy. document.layers

IE


这篇关于IE / Mozilla WYSIWYG编辑器 - IE和queryCommandEnabled的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆