Javascripters:
I have a page with an iframe inside. Let's say the iframe looks like this:
<script src="/javascripts/prototype.js" type="text/javascript" />
....
<iframe id='grinder' src='sample.htm l' >
</iframe>
That prototype.js gives us goodies like $(). And sample.html looks a little
bit like this:
<html><body bgcolor='silver '>
<span id='update_me'> yo</span>
</body></html>
Now I want to write a function that pushes some JavaScript into the iframe,
and evaluates it there. Should I use eval()? Is there some way to make
eval() execute in a frame's context?
Or should I foolishly write a function, in another js header, like this?
function update_grinder( nu_script)
{
var grinder = $('grinder');
if (grinder)
{
var doc = grinder.content Document;
if (!doc) doc = grinder.documen t;
if (doc)
{
doc.body.innerH TML += '<script>' + nu_script + '</script>';
return;
}
}
document.write( " your browser lacks decent iframes");
}
And that doesn't work. The iframe appears to twitch (it will lose a
selection emphasis, for example), but it doesn't evaluate my script.
(For the script.aculo.us-enlightened, the script is just
Element.update( "update_me" , "here I B"), and it is correctly escaped and
transmitted. alert() statements can see it, just before the innerHTML+= line
where it does not work. Without the <scripttags, the new JS appears as
source, and with them it simply doesn't evaluate.
Can't I just say something obvious like doc.body.script = nu_script, or
less??
Please don't ask why I want to do this; I'm not attacking someone else's
page, or trying to write a public site using extra-fragile code. I just ...
need to do it!
--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!