Site Navigation

Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Monday, October 19, 2009

bug 234 - showModalDialog Array returnValue now fails

Issue: #234
Affects: IE6, IE7, IE8

We haven't discovered if this bug is exclusive to VBScript or if it affects JavaScript too (but feel free to update us in the comments if you know).

If you downloaded the latest IE Cumulative Security Update for October 2009 security patch, which "fixed" Microsoft Knowledge Base Article 974455 then you may have noticed that the showModalDialog documentation indicates that the window.returnValue accepts an Array.

However after updating KB974455, there was an undocumented change that now Array return values are no longer allowed.

So what can you do if you depend on this non-standard dialog? Well, the workaround is ugly but there hasn't been confirmation from Microsoft that this bug was introduced - nor that a fix is on the way.



Known Workarounds: One. Use something other than an Array and handle the return value accordingly.

Example Workaround Code:

On the Popup window:

<script type="text/vbscript">
//was
window.returnValue = arrayValue;

//now use
arrString = Join(arrayValue, ";");
window.returnValue = arrString;
</script>



On the Calling window (e.g. Opener):

<script type="text/vbscript">
//was
retArray = window.showModalDialog( ... );

//now use
tempRetArray = window.showModalDialog( ... );
retArray = Split(tempRetArray, ";");
</script>



Related Issues: None.



Bug/Site Feedback |
Submit a bug

Sunday, December 28, 2008

bug 433 - no Array.indexOf( value ) in IE6 IE7 or IE8

Issue: #433
Affects: IE6, IE7, IE8

As one of the basic JavaScript data types Arrays are great for storing lists of data. You can sort them, push, pop, splice & join them!

However in IE you can't find the index of a value in your array using the native .indexOf( value ) method. Likewise the .lastIndexOf( value ) method won't work in IE either.


Example:

<script type="text/javascript">
var foo = [];
foo.push('aaa');
foo.push('bbb');
foo.push('ccc');
foo.push('ddd');
alert(foo.indexOf('ccc'));
</script>


In good modern browsers this will alert "2" but in IE you will just get an error.


Known Workarounds: One. You'll need to prototype your own. (thanks to jcartledge for pointing out that we missed posting the workaround)


<script type="text/javascript">
if(isIE){
Array.prototype.indexOf = function(k){
var len = this.length;
for(i=0;i<len;i++){
if(this[i] == k){
return i;
}
}
return -1;
};
}

if(isIE){
Array.prototype.lastIndexOf = function(k){
var len = this.length;
for(i=len-1;i>-1;i--){
if(this[i] == k){
return i;
}
}
return -1;
};
}
</script>



Related Issues: (bug 181), (bug 253).

Bug/Site Feedback |
Submit a bug

Saturday, May 10, 2008

bug 253 - more Array issues in IE

Issue: #253
Affects: IE6, IE7, IE8, IE9 PP4

This is more of a minor issue, but its just one more thing you'll need to watch out for.

Example:

<script type="text/javascript">
var foo = ['a','b','c','x','y','z',];
alert(foo.length);
</script>


What would you expect in the alert? 6? Well yes, but not in IE. IE will add a 7th element to the array, which is "undefined".

Think about that for a moment. If the so-called 7th element is "undefined", then why is it there? IE just told us that it is not defined!


Known Workarounds: One. Just be sure that all your Array definitions are "clean" especially if they are generated with some server side code.

Example Workaround Code:

<script type="text/javascript">
var foo = ['a','b','c','x','y','z'];
alert(foo.length);
</script>



Related Issues: (bug 230), (bug 181).

Bug/Site Feedback |
Submit a bug

Wednesday, March 26, 2008

bug 181 - can't subclass an Array in IE

Issue: #181
Affects: IE6, IE7, IE8 Beta 1
Fixed In: IE8

MSIE Feedback ID: 334333 (related to the attributes Array)

The #1 rule in OOP (Object Oriented Programing) is that you don't prototype on native objects. This is why many developers do not like the Prototype.js and similar JS Libraries, and where designing for expected behavior of objects is key.

Lets say you want to subclass the Array object, so that you can enjoy using an .each() method on an Array, in browsers before Firefox 3 etc.

No problem, just add this:

Example:

<script type="text/javascript">
var MyArray = function(){
//define your "class"
};
MyArray.prototype = new Array;
//now add your method...
MyArray.prototype.each = function(ref){
//do your magic...
}
</script>


This will work perfectly fine in all browsers, except IE. IE will not update the MyArray instances properly to return the correct length when requested. This of course is rather catastrophic, as it is the only way to know how "big" the array is when iterating over it!

Curious as to why it doesn't work? Well the folks at Microsoft's JScript team let the cat out of the bag and it turns out, that internally it isn't an Array, but rather a HashTable, thus explaining why the performance (pre IE8) was horribly slow, and sub classing just wasn't an option.



Known Workarounds: None. Well, this isn't entirely true. If you "steal" an array from another frame, you can cater it to your needs, but it gets quite involved and it still isn't a true sublass (e.g. you can't re-subclass it) See Dean Edwards Blog post here for more info.


Related Issues: None.

Bug/Site Feedback |
Submit a bug