htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
browser detection IE5.5 or Moz ?


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


spinnergy
Novice

Aug 19, 2003, 11:05 AM

Post #1 of 8 (1854 views)
Shortcut
browser detection IE5.5 or Moz ? Can't Post

Can someone tell me if there is a client side (javascript) detection/sniffer routine that will allow me to determine true/false if the user has a browser that supports HTMLarea???

This would be IE5.5 or any mozilla build > 1.3

In the past I have tried this, but it is now not working in latest Moz build:

function doCanEdit(){
// this script sniffs the user agent to determine if designMode is available
var myDom = navigator.appName.indexOf("Microsoft")!=-1 ? x8receiver : window.document.x8receiver;

if(document.designMode)
{
myDom.SetVariable("_root.designMode","true");
}
else
{
myDom.SetVariable("_root.designMode","false");
}
}


mgifford
Novice

Oct 15, 2003, 1:40 PM

Post #2 of 8 (1798 views)
Shortcut
Re: [spinnergy] browser detection IE5.5 or Moz ? [In reply to] Can't Post

Was quite hoping that someone would have responded to this one. it should be a pretty simple javascript trick to determine if it is either moz 1.3 or ie5.5 and I would think it would be built into the basic install of htmlArea...

Galeon does a decent effort of implementing it, but well you just can't edit anything. This is what I've tried, but it still isn't working.

I almost got javascript working based on:
http://www.gemal.dk/browserspy/basic.html



Code
function checkIt(string) { 
place = detect.indexOf(string) + 1;
thestring = string;
return place;
}

function useHTMLarea() {

var detect = navigator.userAgent.toLowerCase();
var OS, browser, version, thestring, place;
if (checkIt('konqueror')) {
browser = "Konqueror";
OS = "Linux";
} else if (checkIt('safari')) browser = "Safari";
else if (checkIt('omniweb')) browser = "OmniWeb";
else if (checkIt('k-meleon')) {
browser = "K-Meleon";
var rv = detect.match(/k-meleon ([\w.]+)/);
if (rv) {
rv = rv[0];
version = rv.substr(3);
}
}
else if (checkIt('opera')) browser = "Opera";
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) {
browser = "Internet Explorer";
is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
}
else if (!checkIt('compatible')) {
browser = "Netscape Navigator"
version = detect.charAt(8);
if (typeof(navigator.product) != "undefined") {
browser = "Mozilla";
rv = navigator.userAgent.match(/([Mozilla ]?Firebird)\/([\w|\+.]+)/);
if (rv) {
browser = rv[1];
version = rv[2];
} else {
rv = navigator.userAgent.match(/rv:([\w|\+.]+)/);
if (rv) {
rv = rv[0];
version = rv.substr(3);
}
}
}
}else browser = "An unknown browser";
if (!version) {
version = detect.charAt(place + thestring.length);
}


var browsername = "";
if (browser)
browsername += browser;
if (version)
browsername += " " + version;

if ((browser == "Mozilla" && version >= 1.3) || (browser == "Internet Explorer" && is_ie5_5up == true)) {
HTMLArea.replace('en'); HTMLArea.replace('fr');
}
}


Mozilla's javascript console gives me the following error:

Error: detect is not defined
Source File: http://www.be.ca/admin/BE_sectionAdmin.php?submit=edit&sectionID=1&sectionID=1
Line: 96

But I can't see what is different with it than the code on browserspy.

If someone who knows javascript (and there must be a bunch here) could let me know what's wrong here that would be great. Would also be good to filter out all of the extra code which isn't at all useful to the purpose at hand.

Mike


nels
Novice

Oct 16, 2003, 12:38 PM

Post #3 of 8 (1781 views)
Shortcut
Re: [mgifford] browser detection IE5.5 or Moz ? [In reply to] Can't Post

detect is declared as a local variable within useHTMLarea(), so to checkIt() it is undefined. Move the declaration outside the function to make it global, or pass detect to checkIt() as a second parameter.


mgifford
Novice

Oct 16, 2003, 10:48 PM

Post #4 of 8 (1774 views)
Shortcut
Re: [nels] browser detection IE5.5 or Moz ? [In reply to] Can't Post

That was very helpful for resolving the problem with detect, thanks!

I wasn't able to get it to recognize the difference between Galeon & Mozilla though.

Still requires a lot more work.

Mike


mgifford
Novice

Oct 17, 2003, 8:56 AM

Post #5 of 8 (1755 views)
Shortcut
Re: [mgifford] browser detection IE5.5 or Moz ? [In reply to] Can't Post

I was given another suggestion from a user on comp.lang.javascript:


Quote
What objects does it use that only IE5.5 and Mozilla 1.3 have? Test for those.

For example, if it uses document.getElementById, test for that.

if (document.getElementById)
{
// invoke
}
else
{
alert("you aren't using the right browser.");
}

Best way to not get into trouble with browser detection is to detect for objects you use.


I don't know what the javascript tools which were introduced by IE 5.5 or Mozilla 1.3, but I do agree that this would be one of the easiest ways to find out if the browser could handle htmlArea properly.

In Mozilla I'd think it would be something like this:
document.getElementById("edit").contentDocument.designMode="on";

From looking here:
http://www.mozilla.org/editor/midas-spec.html

I tried to find the equivilant with IE, but couldn't find anything that made sense to me here:
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/contentEditable.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmshtml/html/mshtmleditplatf.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie55/html/dnie55ie55.asp

Mike


nels
Novice

Oct 17, 2003, 11:30 AM

Post #6 of 8 (1751 views)
Shortcut
Re: [mgifford] browser detection IE5.5 or Moz ? [In reply to] Can't Post

I agree that object detection would be a better approach, and I have been looking for the appropriate objects to test for. The following code appears to work, as far as I have been able to test:

if(document.all && document.designMode) {
// IE
}
else if(document.designMode) {
// W3C/Moz
}
else {
// other
}

This accepts Win/IE 6.0 and Mozilla and Netscape7 on MacOS X, and it rejects Opera on Windows and Safari and IE 5.2 on MacOS X. I have not been able to test it on Win/IE 5.0 and 5.5. If anyone has these (and any other) browsers available and can test this on them, please post the results. It would be a good thing if we could replace the checkSupportedBrowser() function in HTMLArea with an object detection-based version, because the current version fails on Safari and Mac/IE5, at least.


mgifford
Novice

Oct 17, 2003, 1:20 PM

Post #7 of 8 (1745 views)
Shortcut
Re: [nels] browser detection IE5.5 or Moz ? [In reply to] Can't Post

Nels, this was what I was looking for, thanks!

if((document.all && document.designMode) || (document.designMode)) {
HTMLArea.replace('en');
}

This worked as expected in Linux:
htmlArea not appearing with:
Galeon 1.2.11, Opera 7.11, Konqueror 3.05
htmlArea appearing with:
Mozilla 1.4

I also tested this in a Windows '98 setting, and it also behaved properly.
htmlArea not appearing with:
Opera 7.01
htmlArea appearing with:
Mozilla 1.5b, IE 6.028, Netscape 7.1

I extended the code a bit further to allow a radio button to turn on/off htmlArea to allow for other forms of editing the same document.


Code
<html> 
<head>
<script language="javascript">
<!-- Script Begin
function BE_chooseEditor(loadOnce) {

// if IE 5.5 or W3C/Moz 1.3+
if((document.all && document.designMode) || (document.designMode)) {

// WIKI Text
if (document.editNew.content_type[0].checked) {
if (loadOnce == 1) {
loadOnce = 2;
window.location.reload();
}
}

// Plain Text
if (document.editNew.content_type[1].checked) {
if (loadOnce == 1) {
loadOnce = 2;
window.location.reload();
}
}

// Extended Translation
if (document.editNew.content_type[2].checked) {
if (loadOnce == 1) {
loadOnce = 2;
window.location.reload();
}
}

// HTML or htmlArea
if (document.editNew.content_type[3].checked) {
HTMLArea.replace('en'); HTMLArea.replace('fr');
}
}
}
</head>

<body>

<form>

<input type=radio name=content_type value="wiki" onClick="BE_chooseEditor(1);">Wiki Text
<input type=radio name=content_type value="plain" onClick="BE_chooseEditor(1);">Plain Text
<input type=radio name=content_type value="exttrans" onClick="BE_chooseEditor(1);">Extended Translation
<input type=radio name=content_type value="html" onClick="BE_chooseEditor(1);"> HTML

</form>
</body>
</html>


This works fine too everywhere but IE. In IE, the refresh pulls all of the data fresh from the web site, so you can't actually switch between the types of editors.

This code will be used in http://www.back-end.org's next release.

Mike


(This post was edited by mgifford on Oct 17, 2003, 1:28 PM)


nels
Novice

Oct 17, 2003, 3:56 PM

Post #8 of 8 (1736 views)
Shortcut
Re: [mgifford] browser detection IE5.5 or Moz ? [In reply to] Can't Post

I still haven't confirmed this in a browser test, but it looks like the designMode property is supported by Win/IE5.0, so the test fails to exclude IE5.0. The only document properties I have found that were new with 5.5 are URLUnencoded and the namespaces[] collection. contentEditable was also new with IE5.5, but I haven't found a way to make it work yet (it's not a document property), so for now the best I can come up with is to modify the script as follows:

if(document.all && document.URLUnencoded) {
alert("IE5.5+");
}
else if(document.designMode) {
alert("W3C/Mozilla");
}
else {
alert("Not supported");
}

We also still need to verify whether designMode was supported before Moz 1.3.

nels

 
 
 


Search for (options)