在另一帧上强制javascript [英] foist javascript upon another frame

查看:77
本文介绍了在另一帧上强制javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javascripters:


我的页面里面有一个iframe。让我们说iframe看起来像这样:


< script src =" /javascripts/prototype.js"类型= QUOT;文本/ JavaScript的" />

....

< iframe id =''grinder''src =''sample.html''>

< / iframe>


那个prototype.js给了我们好吃的东西,比如$()。而且sample.html看起来有点像这样:
有点像:


< html>< body bgcolor =''silver''>

< span id =''update_me''> yo< / span>

< / body>< / html>


现在我想写一个函数将一些JavaScript推入iframe,

并在那里进行评估。我应该使用eval()吗?有没有办法让

eval()在一个框架的上下文中执行?


或者我应该愚蠢地写一个函数,在另一个js头文件中,像这样?


函数update_grinder(nu_script)

{

var grinder = $(''grinder'');


if(grinder)

{

var doc = grinder.contentDocument;

if( !doc)doc = grinder.document;

if(doc)

{

doc.body.innerHTML + =''< script> ;''+ nu_script +''< / script>'';

返回;

}

}

document.write(你的浏览器缺乏体面的iframe);

}


这不起作用。 iframe似乎在抽搐(例如,它会失去一个
选择重点),但它并没有评估我的剧本。


(对于script.aculo.us-enlightened,脚本只是

Element.update(" update_me"," here I B"),它被正确转义并且

发送.warning()语句可以看到它,就在innerHTML + = line

之前它不起作用。没有< scripttags,新的JS显示为

来源,并且与它们只是没有评价。


我不能只说一些像doc.body.script = nu_script或
$ b这样明显的东西。 $ b少??


请不要问为什么我要这样做;我不是在攻击别人的

页面,或尝试使用脆弱的代码编写公共站点。我只是...

需要这样做!


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!!!

解决方案

()。而且sample.html看起来有点像这样:
有点像:


< html>< body bgcolor =''silver''>

< span id =''update_me''> yo< / span>

< / body>< / html>


现在我想写一个函数将一些JavaScript推入iframe,

并在那里进行评估。我应该使用eval()吗?有没有办法让

eval()在一个框架的上下文中执行?


或者我应该愚蠢地写一个函数,在另一个js头文件中,像这样?


函数update_grinder(nu_script)

{

var grinder =


< blockquote>(''grinder'');


if(grinder)

{

var doc = grinder.contentDocument;

if(!doc)doc = grinder.document;

if(doc)

{

doc。 body.innerHTML + =''< script>''+ nu_script +''< / script>'';

return;

}

}

document.write(你的浏览器缺乏体面的iframe);

}


那不是不行。 iframe似乎在抽搐(例如,它会失去一个
选择重点),但它并没有评估我的剧本。


(对于script.aculo.us-enlightened,脚本只是

Element.update(" update_me"," here I B"),它被正确转义并且

发送.warning()语句可以看到它,就在innerHTML + = line

之前它不起作用。没有< scripttags,新的JS显示为

来源,并且与它们只是没有评价。


我不能只说一些像doc.body.script = nu_script或
$ b这样明显的东西。 $ b少??


请不要问为什么我要这样做;我不是在攻击别人的

页面,或尝试使用脆弱的代码编写公共站点。我只是...

需要这样做!


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!!!


Phlip在12/16/2006上说了以下内容1:11 AM:


Javascripters:


我的页面里面有一个iframe。让我们说iframe看起来像这样:


< script src =" /javascripts/prototype.js"类型= QUOT;文本/ JavaScript的" />



< script type =" text / javascript" src =" /.../& quot;>< / script>


不要在一般情况下使用XHTML样式。事实上原型得到了加载
是惊人的。


< iframe id =''grinder''src =''样本.html''>

< / iframe>


那个prototype.js给了我们好东西,比如


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.html'' >
</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.contentDocument;
if (!doc) doc = grinder.document;
if (doc)
{
doc.body.innerHTML += ''<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!!!

解决方案

(). 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.contentDocument;
if (!doc) doc = grinder.document;
if (doc)
{
doc.body.innerHTML += ''<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!!!


Phlip said the following on 12/16/2006 1:11 AM:

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" />

<script type="text/javascript" src="/.../"></script>

Don''t use XHTML style in a general context. The fact that prototype got
loaded at all is amazing.

<iframe id=''grinder'' src=''sample.html'' >
</iframe>

That prototype.js gives us goodies like


这篇关于在另一帧上强制javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆