A simple javascript console

L

litchie

Hi, there

I am trying to write a web based javascript console, here it is:

http://litchie.net/programs/jsconsole.html

However, I found the key event processing is nightmare to keep
compatible between different browsers. If you are interested, please
read the source and share your ideas how to achieve same functionality
with simpler code.

thanks
litchie
 
D

David Mark

Hi, there

I am trying to write a web based javascript console, here it is:

http://litchie.net/programs/jsconsole.html

However, I found the key event processing is nightmare to keep
compatible between different browsers. If you are interested, please
read the source and share your ideas how to achieve same functionality
with simpler code.

No need to read the source. The first script element tells the tale:

<script type="text/javascript" src="../scripts/browser-detect.js"></
script>

So obviously it is a nightmare. Get rid of that first. Your app will
likely break as a result. Fix those problems and see where you are at
that point.
 
M

Martin Rinehart

David said:
<script type="text/javascript" src="../scripts/browser-detect.js"></
script>

So obviously it is a nightmare. Get rid of that first. Your app will
likely break as a result. Fix those problems and see where you are at
that point.

David's suggesting that you drop the old technique:

if (browser === MSIE) { MSIE code }
else {standard code}

This is problem-riddled. Check for the features you need:

if ( standardMethod ) {standard code}
else if (nonstandardMethod) {other code}
else if ...

However, useful as that suggestion is, it will not guarantee that you
get around the problems. I've posted a widget here that runs on Opera
and nothing else.
 
D

David Mark

David's suggesting that you drop the old technique:

if (browser === MSIE) { MSIE code }
else {standard code}

This is problem-riddled. Check for the features you need:

if ( standardMethod ) {standard code}
else if (nonstandardMethod) {other code}
else if ...

However, useful as that suggestion is, it will not guarantee that you
get around the problems. I've posted a widget here that runs on Opera
and nothing else.

Depends what the problems are. And that must have been a really
troubled widget. Perhaps you should post it again.
 
D

Doug Gunnoe

L

litchie

David's suggesting that you drop the old technique:

if (browser === MSIE) { MSIE code }
else {standard code}

This is problem-riddled. Check for the features you need:

if ( standardMethod ) {standard code}
else if (nonstandardMethod) {other code}
else if ...

However, useful as that suggestion is, it will not guarantee that you
get around the problems. I've posted a widget here that runs on Opera
and nothing else.

The strange thing is that, IE can't catch the "(" key by onkeypress
event, but Firefox/Safari can; And IE uses the e.keyCode as charCode
while Firefox/Safari uses e.charCode. Opera has shortcut keys that my
app can't receive those keys, I give it up finally.

So the only way I can do is to treat different browsers differently.
 
D

David Mark

The strange thing is that, IE can't catch the "(" key by onkeypress
event, but Firefox/Safari can; And IE uses the e.keyCode as charCode
while Firefox/Safari uses e.charCode.  Opera has shortcut keys that my
app can't receive those keys, I give it up finally.

So the only way I can do is to treat different browsers differently.

No, if you are incapable, then the best bet is to pack it in.
"Treating browsers differently" might create the illusion you are
capable (as libraries do), but it is not a solution.
 
D

Doug Gunnoe

The strange thing is that, IE can't catch the "(" key by onkeypress
event, but Firefox/Safari can; And IE uses the e.keyCode as charCode
while Firefox/Safari uses e.charCode.  Opera has shortcut keys that my
app can't receive those keys, I give it up finally.

So the only way I can do is to treat different browsers differently.

Browser detection as a means of handling stuff is faulty and
needlessly complex. And has for some time been discarded.

And what people here are telling you is that you should test for the
features and properties you're interested in rather than for the
browser.

Google "feature sensing"
 
D

David Mark

Browser detection as a means of handling stuff is faulty and
needlessly complex. And has for some time been discarded.

And what people here are telling you is that you should test for the
features and properties you're interested in rather than for the
browser.

Google "feature sensing"

"Feature testing" will likely get more hits.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,135
Messages
2,570,783
Members
47,339
Latest member
flaviu2

Latest Threads

Top