473,657 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE/Mozilla WYSIWYG editor - problems with IE and queryCommandEna bled

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
queryCommandEna bled('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="DoText Format('forecol or','')"
id="forecolor" >
<iframe width="175" height="125" id="forecolor0 " src="palette.ht ml"
style="visibili ty: hidden; position: absolute; left: 0px; top:
0px;"></iframe>

palette.html is like this:
<html>
<head>
<title>Color Palete</title>
<script language="JavaS cript" type="text/javascript">
<!--
function selectColor(col or){
self.parent.set Color(color);
}
function InitColorPalett e(){
if (document.getEl ementsByTagName )
var x = document.getEle mentsByTagName( 'TD');
else if (document.all)
var x = document.all.ta gs('TD');
for (var i=0;i<x.length; i++){
x[i].onclick = click;
}
}
function click(){
str=this.id;
color=str.repla ce('c','#');
selectColor(col or);
}
-->
</script>
<style type="text/css">
<!--
html,body{margi n: 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="InitCol orPalette()">
<table border="0" cellpadding="0" cellspacing="2" >
<tr>
<td id="cFFFFFF" bgcolor="#FFFFF F" width="15" height="15">&nb sp;</td>
<td id="cFFCCCC" bgcolor="#FFCCC C" width="15" height="15">&nb sp;</td>
....

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

function DoTextFormat(co mmand, option){
if((command=='f orecolor') || (command=='hili tecolor')){
parent.command= command;
layerid=command +'0';
buttonElement=d ocument.getElem entById(command );

document.getEle mentById(layeri d).style.left=g etOffsetLeft(bu ttonElement)
+ 'px';

document.getEle mentById(layeri d).style.top=(g etOffsetTop(but tonElement)
+ buttonElement.o ffsetHeight) + 'px';
if(document.get ElementById(lay erid).style.vis ibility=='hidde n')
document.getEle mentById(layeri d).style.visibi lity='visible';
else{
document.getEle mentById(layeri d).style.visibi lity='hidden';
}

//get current selected range
var
sel=document.ge tElementById('i View').contentW indow.document. selection;
if(sel!=null){
rng=sel.createR ange();
}
}else{

if(document.get ElementById('iV iew').contentWi ndow.document.q ueryCommandEnab led(command)){

document.getEle mentById('iView ').contentWindo w.document.exec Command(command ,
false, option);
return true;
}else return false;
}
document.getEle mentById('iView ').contentWindo w.focus();
}

function setColor(color) {
elem=command+'0 ';
if(browser.isIE 5up){
//retrieve selected range
var
sel=document.ge tElementById('i View').contentW indow.document. selection;
if(sel!=null){
var newselectionRan ge=sel.createRa nge();
newselectionRan ge.select();
}
}else{
document.getEle mentById('iView ').contentWindo w.focus();
}

if(document.get ElementById('iV iew').contentWi ndow.document.q ueryCommandEnab led(command)){

document.getEle mentById('iView ').contentWindo w.document.exec Command(command ,
false, color);
}else{

alert("queryCom mandEnabled("+c ommand+") returned false. Cannot set color
to "+color);
// close palette before exiting function
document.getEle mentById(elem). style.visibilit y='hidden';
return false;
}
document.getEle mentById('iView ').contentWindo w.focus();
document.getEle mentById(elem). style.visibilit y='hidden';
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 5923
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="javas cript">
function test() {
if (frames.length && frames['iView'] && frames['iView'].document &&
frames['iView'].document.query CommandEnabled) {
alert(frames['iView'].document.query CommandEnabled( "forecolor" ))
}
else
if (document.getEl ementById &&
document.getEle mentById('iView ').contentWindo w &&
document.getEle mentById('iView ').contentWindo w.queryCommandE nabled)

alert(document. getElementById( 'iView').conten tWindow.documen t.queryCommandE n
abled("forecolo r"))
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.ne t> 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.ne t> 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.getEl ementByID (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
queryCommandEna bled('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.ne t> writes:
NS4 is very easy. document.layers
OmniWeb.
<URL:http://www.omnigroup.c om/mailman/archive/omniweb-l/2002-June/007067.html>
IE$ is document.all && !document.getEl ementByID (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.ne t> 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.getEl ementByID (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.ne t> 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.getEle mentById 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(func tion(){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_entr y.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.prototyp e.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.ne t> 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.getEle mentById 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(func tion(){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_entr y.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.prototyp e.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.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #10

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

Similar topics

6
1997
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 trans-formation. What I'm looking for is an editor that lets me design how I want the result to look, based on a XML file, and automatically generates the XSL needed to obtain the result. Does such a product exist?
5
3848
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 javascript to not invoke the WYSYWYG if a browser that supports it isn't being used. To do that I need to know some very specific stuff about the browser, and the different browsers haven't made this very easy.
3
2232
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 your recommendation for a good wysiwyg HTML editor please. (either free or commercial). I want to build 'quick' web pages with a wysiwyg editor, then 'fine-tune'
4
3024
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; instead of <strong> and so on. Is this a problem with the editor or something else? Does .Net convert it? I had to disable page validate request because of the tags, is there more? Thanks,
1
5189
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 where users can discuss all aspects about their dogs. I wish to enhance the forums form input with a few simple options (bold, cursive and insert link). Preferably a WYSIWYG edit but ill settle for a code creator. (where selected text becomes...
2
2965
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. It partly works in Opera 9 and doesn't work in Internet Explorer 6. This demo uses a hidden iframe containing a document in design mode. <URL: http://peter.michaux.ca/temp/rte/example.html>
27
3820
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 since the last time I authored web pages (using vi), I am looking for a good, "free" WYSIWYG HTML Editor. Now, before ya go and hit the reply key, I've already tinkered with "amaya" which was pretty cool and then I moved to "Nvu", which I like
22
2197
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
2642
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 Dreamweaver and FCKEditor, so those two seem out of the question, even though they do what I want. Basically, I'm looking to make changes mostly to the HTML content of a PHP website, and want to do so in the easiest way possible, preferably...
0
8403
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.