Note that there are some explanatory texts on larger screens.

plurals
  1. POWays to access a JavaScript Object's Property in IE6
    primarykey
    data
    text
    <p>I have a JavaScript object with some properties. Lets say:</p> <pre><code>var haystack = { foo: {value: "fooooo"}, bar: {value: "baaaaa"} }; </code></pre> <p>Now, I want to access one of those properties, but I don't know which one. Luckily, this variable does:</p> <pre><code>var needle = "foo"; </code></pre> <p>In modern browsers I seem to be able to do the following and it works:</p> <pre><code>haystack[needle].value; # returns "fooooo" </code></pre> <p>But in IE6 it throws a wobbly, <code>haystack[...] is null or not an object</code>.</p> <p>Is there a way to achieve what I'm trying to achieve in IE6? If so, how so?</p> <hr> <p>EDIT - Adding further information in response to the comments below...</p> <hr> <p>What I am trying to achieve is actually related to CKEditor. I haven written a plugin image manager that opens in an iframe.</p> <p>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).</p> <p>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:</p> <pre><code>&lt;iframe&gt;&lt;!-- Image manager --&gt;&lt;/iframe&gt; &lt;input type="hidden" id="ckinstance" value="article_body" /&gt; </code></pre> <p>So then, inside the iframe when an image is selected to be inserted I have some JavaScript that looks like this:</p> <pre><code>var CKEDITOR = window.parent.CKEDITOR; var instance = window.parent.$('#ckinstance').val(); var img = '&lt;img src="/whatevers/been/selected" /&gt;'; CKEDITOR.instances[instance].insertHtml(img); window.parent.$.modal.close(); </code></pre> <p>This works fine in FF, Chrome, etc. Just IE6 is complaining with:</p> <pre><code>CKEDITOR.instances[...] is null or not an object. </code></pre> <p>EDIT 2</p> <p>I've just done some debugging and actually it looks like IE6 is failing on <code>window.parent.$('#ckinstance').val()</code> and is returning undefined.</p> <p>So the original problem that I've described is not the problem at all.</p> <p>Still need help though :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload