I have a JavaScript object with some properties. Lets say:
var haystack = {
foo: {value: "fooooo"},
bar: {value: "baaaaa"}
};
Now, I want to access one of those properties, but I don't know which one. Luckily, this variable does:
var needle = "foo";
In modern browsers I seem to be able to do the following and it works:
haystack[needle].value; # returns "fooooo"
But in IE6 it throws a wobbly, haystack[...] is null or not an object
.
Is there a way to achieve what I'm trying to achieve in IE6? If so, how so?
EDIT - Adding further information in response to the comments below...
What I am trying to achieve is actually related to CKEditor. I haven written a plugin image manager that opens in an iframe.
What I then want to achieve is to place the chosen image back in the correct instance of CKEditor (and there can be more than one instance on some pages).
What I have done (and I know this is an ugly hack), when the iframe is opened I have put a hidden field next to it with the name of the instance. So the parent page contains some markup like this:
<iframe><!-- Image manager --></iframe>
<input type="hidden" id="ckinstance" value="article_body" />
So then, inside the iframe when an image is selected to be inserted I have some JavaScript that looks like this:
var CKEDITOR = window.parent.CKEDITOR;
var instance = window.parent.$('#ckinstance').val();
var img = '<img src="/whatevers/been/selected" />';
CKEDITOR.instances[instance].insertHtml(img);
window.parent.$.modal.close();
This works fine in FF, Chrome, etc. Just IE6 is complaining with:
CKEDITOR.instances[...] is null or not an object.
EDIT 2
I've just done some debugging and actually it looks like IE6 is failing on window.parent.$('#ckinstance').val()
and is returning undefined.
So the original problem that I've described is not the problem at all.
Still need help though :)