javascript adding code to a parent iframe
<p>been struggling with this for some time now, im trying to add a function to the main window from an iframe, but the only way i can get it to work is by providing an eval function in the main window and passing it a string, such as:</p>

<pre><code>--main window--
    function evalcmd(c){
      eval(c);
    }
--iframe--
    parent.evalcmd('alert(location.href)');
</code></pre>

<p>ideally i would like something of the form</p>

<pre><code>--iframe--
    parent.myalert=new Function('alert(location.href);');
</code></pre>

<p>however this seems to be called from the context of the iframe, ie the alert references the iframes filename</p>

<p>sorry new edit</p>

<p>the alert is trying to show the context that the new Function operates in, if i had</p>

<pre><code>--main window--
&lt;div id="txt1" style="left:50px;"&gt;somettxt&lt;/div&gt;

--iframe--
parent.movetxt=new Function("document.getElemenById('txt1').style.left='35px';");
</code></pre>

<p>this would throw an error, element 'txt1' not found in iframe
however,</p>

<pre><code>--main window--
function evalcmd(c){
  eval(c);
}
--iframe--
parent.evalcmd("document.getElemenById.('txt1').style.left='35px';");
</code></pre>

<p>would be fine, 
is there a way to have this functionality without the use of eval?
i basically have a lot of code i want to add to the parent window, so dont want to have to go through adding parent. to varname/functionname on all references</p>
