Skip navigation.

exploreopera

| Help

Sign up | Help

Posts tagged with "javascript"

Poor Javascript Coding Quality

, , ,

What is it with Javascript programmers these days? Doesn't anybody know how to program?

I was investigating why tinyMCE 2 (.1.3) is failing in Opera in some circumstances, and what did I find?

Exhibit 1:
if (tos.getEditorTemplate) editorTemplate = tos.getEditorTemplate(this.settings, this.editorId);
deltaWidth = editorTemplate.delta_width ? editorTemplate.delta_width: 0;
The if statement is there for a reason - to initialize editorTemplate to something useful - but what happens if the statement is false? editorTemplate does not get initialized. Look at the following statement - the potentially uninitialized editorTemplate is used! That would generate an error in any browser.

Exhibit 2:
getRng: function() {
  var s = this.getSel();
  if (s == null) return null;
  if (tinyMCE.isRealIE) return s.createRange();
  if (tinyMCE.isSafari && !s.getRangeAt) return '' + window.getSelection();
  if (s.rangeCount > 0) return s.getRangeAt(0);
  return null
},
isCollapsed: function() {
  var r = this.getRng();
  if (r.item) return false;
  return r.boundingWidth == 0 || this.getSel().isCollapsed
},
getRng is obviously capable of returning null. The very next function, isCollapsed, calls it and immediately uses the returned value without checking for null. That will generate an error in any browser.

It doesn't matter how other browsers somehow manage to avoid these obvious bugs - this is just plain crappy coding.

The worst thing is, this is typical of the sort of code that makes the web go. It's a wonder it works at all.

Opera 10 is too old!

, , ,

Not that Opera have released version 10 (yet!), but it looks like at least one site is going to reject Opera when they do. And where there's one site, no doubt there's hundreds of others :frown: Thankfully, a quick search doesn't quickly turn up anything similar, although there are plenty of other bad examples.

Anyway, here's the problem code:
if (navigator.userAgent.toLowerCase().indexOf("opera") != -1)
{
   isOpera = true;
   i = navigator.userAgent.indexOf("Opera") + 6;
   v = parseInt(navigator.userAgent.substring(i, i+1));
   if(v < 7)
      isOperaOld = true;
}
Need a clue? The substring will return exactly one character.

If you're one of those people irritated at how poorly Opera appears to handle web site scripting - this is one of the bigger reasons. It's straight-out careless programming without thought.

I'll mention that the site in question isn't delivering bugs to just Opera. Their corresponding IE code had the exact same problem, except that IE is quite a bit further away from version 10 than Opera.

The problem remains for Opera:
  1. Opera release version 10.
  2. Web sites stop working in Opera, all other browsers work fine.
  3. "Opera is a crappy browser, never works!"
Yet, where is the bug? What should Opera do about it? Never release a browser with a version where the first digit is between zero and six inclusive? Will the Opera after 9.5 be 70.0? :insane:

The fastest browser!

, , ,

I just bumped into a comparison of Javascript CSS selector libraries at http://extjs.com/blog/2007/07/10/css-selectors-speed-myths/ . The whole point of the article wasn't to compare browsers, but to compare the speed of various library implementations in different browsers, and to determine which library was fastest overall.

As I read the article, one browser was mentioned several times - Firefox. No other browser was mentioned, other than by phrases like "Performance in other browsers drops significantly".

At the end is a table cross-referencing library runtimes and browsers. One browser was consistently the fastest among all other browsers. This fastest browser wasn't even mentioned once in an article devoted to analysing how fast libraries and browsers are.

That fastest browser was Opera! :D

Head-smacking sniffing stupidity

, , ,

I'm feeling a bit like Hallvord right now :rolleyes:

While doing some web site troubleshooting, I bumped into the following code at Olive Software:
var Mac  =  (navigator.userAgent.indexOf("mac")!=-1)  || (navigator.userAgent.indexOf("Mac")!=-1);
var opnew = (navigator.userAgent.indexOf('Opera 7')!=-1);
var opold = (navigator.userAgent.indexOf('Opera')!=-1);
var msie  =  (navigator.userAgent.indexOf('MSIE')!=-1);
var moz  =  (navigator.userAgent.indexOf('Gecko')!=-1);
var NS6  =  (navigator.userAgent.indexOf('Netscape')!=-1 && navigator.userAgent.indexOf('Gecko')!=-1);
var Nav4  = (document.layers);
var konq = (navigator.userAgent.indexOf('Konqueror')!=-1);
if (opold && msie || opold){var opold=1; msie=0;}
if (msie && !opold){msie=1;}
if(opnew && opold){opold=0;}
if(msie || moz || opnew){var dom = 1;}

Whoever coded that was obviously having a really bad day. Maybe their cat had died, but it must have been something seriously distracting.

I mean, translate their "opnew" into English: "It's a new version of the Opera browser if it's version 7 and identifying itself as IE or Mozilla". That's right, any later versions (like 8 or 9) are old versions, and even version 7 identifying as itself is old!

And people wonder why Opera appears to have a hard time handling web sites?
July 2008
SMTWTFS
June 2008August 2008
12345
6789101112
13141516171819
20212223242526
2728293031