473,390 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

IE/Mozilla WYSIWYG editor - problems with IE and queryCommandEnabled

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.

Jul 20 '05 #1
12 5892
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>


Jul 20 '05 #2
"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).

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.'
Jul 20 '05 #3

"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$ is document.all && !document.getElementByID (sp?)

IE4 typically needs no extra coding. NS4 should be supported by very
low-level scripts (typically wrappers for finding and positioning elements.)

|
| 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.'
Jul 20 '05 #4
Justin Koivisto wrote:
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.


Hopefully this will help get some input on the problem - here is a URL
to view it all:
http://waf.rangenet.com/test/WYSIWYG-Editor/

As far as I can tell, this is the last piece of the puzzle for me to get
it into the CMS that I am developing. Everything works fine in Mozilla
(and what I've tested thus far in NS6+), but the color issue isn't
working with IE. Everything for this project was going quite smoothly
for not doing JS before, but this part is really getting to me (I've let
it sit for a couple months and am just getting back to it now).

Also, any pointers on how to create tables in IE as done in Mozilla
would be quite helpful as well. TIA!

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

Jul 20 '05 #5
"Nobody" <no**@nope.net> writes:
NS4 is very easy. document.layers
OmniWeb.
<URL:http://www.omnigroup.com/mailman/archive/omniweb-l/2002-June/007067.html>
IE$ is document.all && !document.getElementByID (sp?)
That might be unique (since hopefully no new browser will ever be made
without getElementById).
IE4 typically needs no extra coding. NS4 should be supported by very
low-level scripts (typically wrappers for finding and positioning elements.)


IE 4 lacks a few features that I use often in Javascript (e.g.,
functional arguments to setTimeout/setInterval and to String.replace)
as well as a standards compliant rendering mode.
Ofcourse, the Javascript part can be fixed it with wrappers too.

/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.'
Jul 20 '05 #6

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:n0**********@hotpop.com...
| "Nobody" <no**@nope.net> writes:
|
| > NS4 is very easy. document.layers
|
| OmniWeb.
|
<URL:http://www.omnigroup.com/mailman/arc...une/007067.htm
l>

Thanks. What are those jerks doing? What is the more specific solution to
weed them out of the equation? Create a test layer and see if it actually
has properties?

|
| > IE$ is document.all && !document.getElementByID (sp?)
|
| That might be unique (since hopefully no new browser will ever be made
| without getElementById).

Lets hope!

|
| > IE4 typically needs no extra coding. NS4 should be supported by very
| > low-level scripts (typically wrappers for finding and positioning
elements.)
|
| IE 4 lacks a few features that I use often in Javascript (e.g.,
| functional arguments to setTimeout/setInterval and to String.replace)
| as well as a standards compliant rendering mode.
| Ofcourse, the Javascript part can be fixed it with wrappers too.

Function arguments to setTimeout? Can you elaborate on that one?
String.replace would need a wrapper if you use that.

|
| /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.'
Jul 20 '05 #7
"Nobody" <no**@nope.net> writes:
Thanks. What are those jerks doing? What is the more specific solution to
weed them out of the equation? Create a test layer and see if it actually
has properties?
I would just check for document.getElementById and document.all first
(in that order). If they support either, they will be fine. If not,
then I'll have to rely on document.layers working, and if it doesn't,
it is a doomed browser anyway.
Function arguments to setTimeout? Can you elaborate on that one?
You can use setTimeout in two ways: with a string or a function.
setTimeout("foo=bar;",2000);
or
setTimeout(function(){foo=bar;},2000);

The latter method has several advantages:
- It detects syntax errors early (during parsing, not when the code is run
for the first time);
- I find it easier to separate code and data when the code isn't inside
a string.
- The closure keeps the references to local variables (*much* easier coding!),
while the string is evaluated in the global scope.

Sadly, IE4 only supports the first. The same goes for setInterval.

According to MSDN
(<URL:http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/dhtml_node_entry.asp>)
---
In versions earlier than Microsoft® Internet Explorer 5, the first
argument of setTimeout must be a string. Evaluation of the string is
deferred until the specified interval elapses.
---

String.replace would need a wrapper if you use that.


It doesn't work in IE5.0 either, only in 5.5 and 6.0.

Hmm, in Opera 7, String.prototype.replace is a Javascript function,
not an internal function. I could probably just use that code if I
need it :)

/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.'
Jul 20 '05 #8

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:vf**********@hotpop.com...
| "Nobody" <no**@nope.net> writes:
|
| > Thanks. What are those jerks doing? What is the more specific solution
to
| > weed them out of the equation? Create a test layer and see if it
actually
| > has properties?
|
| I would just check for document.getElementById and document.all first
| (in that order). If they support either, they will be fine. If not,
| then I'll have to rely on document.layers working, and if it doesn't,
| it is a doomed browser anyway.

Makes sense. Doomed browsers indeed.

|
| > Function arguments to setTimeout? Can you elaborate on that one?
|
| You can use setTimeout in two ways: with a string or a function.
| setTimeout("foo=bar;",2000);
| or
| setTimeout(function(){foo=bar;},2000);
|
| The latter method has several advantages:
| - It detects syntax errors early (during parsing, not when the code is run
| for the first time);
| - I find it easier to separate code and data when the code isn't inside
| a string.
| - The closure keeps the references to local variables (*much* easier
coding!),

Bingo was his name-o! That's the one that matters (to me at least.) I'll
keep that in mind for future, but thank goodness that I am not using it
anywhere at present (because I know I don't check for IE4 before setting
timeouts!)

| while the string is evaluated in the global scope.
|
| Sadly, IE4 only supports the first. The same goes for setInterval.

Don't use the latter and can't even remember what it does.

|
| According to MSDN
|
(<URL:http://msdn.microsoft.com/library/de...hop/author/dht
ml/dhtml_node_entry.asp>)
| ---
| In versions earlier than Microsoft® Internet Explorer 5, the first
| argument of setTimeout must be a string. Evaluation of the string is
| deferred until the specified interval elapses.
| ---
|
|
| > String.replace would need a wrapper if you use that.
|
| It doesn't work in IE5.0 either, only in 5.5 and 6.0.

Noted. Can't you check for the existence of the replace method on a string
object (so as to forget the browser versions.)

|
| Hmm, in Opera 7, String.prototype.replace is a Javascript function,
| not an internal function. I could probably just use that code if I
| need it :)

I don't use it on the client side (though I am sure that some of my code
would be made more efficient with it.)

Thanks for your input!

|
| /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.'
Jul 20 '05 #9
On 04 Sep 2003 00:28:21 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
String.replace would need a wrapper if you use that.


It doesn't work in IE5.0 either, only in 5.5 and 6.0.


That could even fail in IE6 since it's a JS method not a DOM method,
and js version is strictly independant from browser version....

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #10
"Nobody" <no**@nope.net> writes:
Noted. Can't you check for the existence of the replace method on a string
object (so as to forget the browser versions.)


The replace function is there, it's just that the replaceText argument
can't be a function in IE 5.0 or earlier. It works in Netscape 4.

Example of replacing with a function:
---
function reverseString(str) {
return str.split("").reverse().join("");
}
var text = "this becomes a weird text";
var newText = text.replace(/\b\w*\b/g,reverseString);
alert(newText);
---

If using a replaceText string, you can also use, e.g., $1 to refer to
the first matched group. This only works in IE5.5+ too. Before that,
the replace method could only replace with a fixed string.

/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.'
Jul 20 '05 #11
ji*@jibbering.com (Jim Ley) writes:
That could even fail in IE6 since it's a JS method not a DOM method,
and js version is strictly independant from browser version....


That is a point, but I believe IE 6 includes JScript 5.6. Perhaps you
could install an earler version of JScript, but I am not sure.

<URL:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriversioninformation.asp>

/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.'
Jul 20 '05 #12
On 04 Sep 2003 01:27:32 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
ji*@jibbering.com (Jim Ley) writes:
That could even fail in IE6 since it's a JS method not a DOM method,
and js version is strictly independant from browser version....


That is a point, but I believe IE 6 includes JScript 5.6.


Oh in reality the chances are very slim, some sort of install problem
whereby jscript.dll couldn't be written is about the only option,
that's not an intentional attempt, not likely ay all, that's what I
was intending to get across with the "strictly" did a very bad job
though. Sorry.

Hun.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lb | last post by:
Hi I'm looking for a wysiwyg XSTL editor, that actually is wysiwyg. So far every product I have tried out seems to have the idea that wysiwyg is just showing the result of an XML - XSL...
5
by: Mike Gifford | last post by:
Hello, htmlArea3 is a great script for those who want a free javascript WYSIWYG editor. The only problem is that it only works in Mozilla 1.3+ & IE 5.5+. I'd like to find some piece of...
3
by: Mel Smith | last post by:
HI Friends, I'm a newbie at html writing but am a computer programmer and use a great editor (The Semware Editor - TSE) for all my coding -- even building my own first web pages. I'd like...
4
by: David Lozzi | last post by:
Howdy, I'm using a WYSIWYG editor called TinyMCE. When I edit some text and then save it back to my SQL server using a SQLCommand, all HTML characters are changed to HTML code, i.e. &gt;strong&lt;...
1
by: Arjen | last post by:
Hi, Im trying to make / looking for a very very simple WYSIWYG editor. Ive made a (ad free) site about dogs but it's attracting way more visitors then I could ever have imagined. I have a forum...
2
by: Peter Michaux | last post by:
Hi, I took apart an existing wysiwyg editor to try to learn how they work and some of the important issues. The following url has my current version that seems to work in Safari 2 and Firefox 2....
27
by: prt7u | last post by:
Howdy, I've started back afte a very long time of working with web pages for an organization that I am affiliated with (personally not professionally). Seeing that technology has advanced a lot...
22
by: iKiLL | last post by:
Hi all I have been asked to develop a solution that is customisable by our clients. It is supposed to run on the Windows Mobile 5.0 CF2.0 environment using Merge Replication.
12
by: Rex | last post by:
Hello, I am a PHP newbie looking for a PHP editor I can use with a WYSIWYG interface for HTML (e.g. like Dreamweaver or Frontpage). I'm running Vista. I am having installation problems with both...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.