Opera and indexOf
Friday January 11, 2008
I have been working on some new ordering pages at work for GRS. This includes the engraved labels, engraved plaques and so on, and today, the safety sign stickers.
I had a great idea yesterday of linking articles from the company blog to individual stickers, so one article for Electrical Warning stickers, one article for No Swimming and so on. Great idea isn’t it? Google should pick up on it and it will generate traffic for the company’s website.
Then I ran into a problem. Because of the way I was handling the sign symbols, I was using an array and happened to use indexOf to find where a word was in the array. Opera and IE(7) were going nowhere with it - FireFox was fine (surprise). Then I found an article at CommaDot, entitled Opera JS Troubleshooting which resolved the issue, apparently a bug with the way Opera handles indexOf (and incidentally, it fixed IE7’s issue with it too). Here it is:
// This is solely to support indexOf in Opera. Not sure of a better way to do this
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(val, fromIndex) {
if (typeof(fromIndex) != ‘number’) fromIndex = 0;
for (var index = fromIndex,len = this.length; index < len; index++)
if (this[index] == val) return index;
return -1;
}
}
Now it all works properly, as it should, setting the document’s title and the h1 title on the page to the correct symbol name.










This blog requires you to login before replying. If you do not have an account you can create one (for free!).