保持对对象的持久引用 [英] keeping a persistent reference to an object

查看:70
本文介绍了保持对对象的持久引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


有没有人知道我可以保留一个对象的方式

然后我可以重复使用?我尝试了使用导航器的各种方法,但由于预先出现问题,这些都在iframe中失败了。


例如:


navigator.stuff = 5;

只要在顶级窗口中完成,
就可以正常工作。但是如果

那么我会这样做:


alert(navigator.stuff);


在子iframe中,我得到''undefined''...几乎就像我以为

引用不同的导航器对象(??)。什么给了?


此外,如果我尝试转而使用top.navigator或

parent.navigator,我会得到权限被拒绝的错误,可能是由于

事实上,我的iframe来自与其父级不同的URL。


必须有一些偷偷摸摸的不道德的做法(使用隐藏的

框架可能吗?),但我在这里结束了我的智慧!


帮助!


谢谢,

Marc

Hi!

Does anybody know of a way that I can keep a reference to an object
that I can then reuse? I tried various approaches using navigator, but
these all fail in an iframe due to premission problems.

For e.g.:

navigator.stuff = 5;

will work fine so long as this is done in the top level window. But if
I then do:

alert(navigator.stuff);

in a child iframe, i get ''undefined''... almost as thought I were
refering to a different navigator object (??). What gives?

Furthermore, if I then try refering instead to top.navigator or
parent.navigator, I get permission denied errors, presumably due to the
fact that my iframe is coming from a different URL than its parent.

There must be some sneaky underhanded way of doing this (using a hidden
frame maybe?), but I''m at my wit''s end here!

Help!

Thanks,
Marc

推荐答案



ma ******** @ gmail.com 写道:



ma********@gmail.com wrote:

有没有人知道我可以保留对象的引用的方式然后我可以重用?我尝试了使用导航器的各种方法,但是由于提交问题,这些都在iframe中失败了。


此外,如果我尝试转而使用top.navigator或
parent.navigator,我会得到许可被拒绝的错误,大概是因为我的事实是iframe来自与其父级不同的URL。

必须有一些偷偷摸摸的不道德的做法(使用隐藏的
框架可能吗?),但我是我的机智'到此结束!
Does anybody know of a way that I can keep a reference to an object
that I can then reuse? I tried various approaches using navigator, but
these all fail in an iframe due to premission problems.
Furthermore, if I then try refering instead to top.navigator or
parent.navigator, I get permission denied errors, presumably due to the
fact that my iframe is coming from a different URL than its parent.

There must be some sneaky underhanded way of doing this (using a hidden
frame maybe?), but I''m at my wit''s end here!




对于来自不同来源的框架/窗口,您将始终遇到禁止您访问的

相同来源政策。


如果您有来自同一来源的框架集文档和框架文档

那么框架应该能够存储内容

parent.variableName

只要框架集文档没有重新加载。


同样来自同一来源的iframe的HTML文档,iframes

可以将内容存储在

parent.variableName

中,只要不重新加载父文档。


-


Martin Honnen
http://JavaScript.FAQTs.com/


ma ******** @ gmail.com 写道:
嗨!

有谁知道我可以的方式保留一个对象的引用
然后我可以重用?我尝试了使用导航器的各种方法,但由于预先设置问题,这些都在iframe中失败。

例如:
navigator.stuff = 5;
Hi!

Does anybody know of a way that I can keep a reference to an object
that I can then reuse? I tried various approaches using navigator, but
these all fail in an iframe due to premission problems.

For e.g.: navigator.stuff = 5;




主页:


self.stuff = 5;

或:

stuff = 5;

或/和:

if(!! parent.myIframe.stuff)

parent.myIframe.stuff = 5;

调用页面:


if(!! parent.stuff)

stuff = parent.stuff;

else

alert('''错误与\'''\\''''''');

如果这不起作用,试试看as:


主页:


< html>

< head>

< script type =" text / javascript">

函数发送(页面,属性,目标)

target.location.href = page +'' ?''+ attrib;

}

< / script>

< / head>

< ; body>

< a href =" pge1.htm" target =" myIframe"

onclick =" send(this.href,this.target,''stuff = 5& name = \''foo \'''');

返回false;">第1页< / a>


< a href =" pge2.htm"

onclick =" send(this.href,''self'',''stuff = 25& name = \''trick'\\''''');

返回false; ">第2页< / a>

< / body>< / html>


被调用页面:

< html>

< head>

< script type =" text / javascript">


function receiv(){

var attrib = this.location.search;

attrib = attrib.substring(1).split(''&' ');

for(var i = 0; i< attrib.length; i ++)

eval(attrib [i]);

}

receiv()


if(!! name)

alert(''name =''+ name);

else

alert(''无变量\''名称''或... \ n'function broken'');


< / script>

< / head>

< / html>


-

Stephane Moriaux et son [moins] vieux Mac



Main page :

self.stuff = 5;
or :
stuff = 5;
or/and :
if(!!parent.myIframe.stuff)
parent.myIframe.stuff = 5;
Called page :

if(!!parent.stuff)
stuff = parent.stuff;
else
alert(''error with \''stuff\'' !'');
And if that doesn''t work, try something as :

Main page :

<html>
<head>
<script type="text/javascript">
function send(page,attrib,target)
target.location.href=page+''?''+attrib;
}
</script>
</head>
<body>
<a href="pge1.htm" target="myIframe"
onclick="send(this.href,this.target,''stuff=5&name= \''foo\'''');
return false;">page 1</a>

<a href="pge2.htm"
onclick="send(this.href,''self'',''stuff=25&name=\''tr ick\'''');
return false;">page 2</a>
</body></html>

Called Page :

<html>
<head>
<script type="text/javascript">

function receiv(){
var attrib = this.location.search;
attrib = attrib.substring(1).split(''&'');
for(var i=0;i<attrib.length;i++)
eval(attrib[i]);
}
receiv()

if(!!name)
alert(''name = ''+name);
else
alert(''no variable \''name\'' or ...\nfunction broken'');

</script>
</head>
</html>

--
Stephane Moriaux et son [moins] vieux Mac


ma********@gmail.com 写道:
有没有人知道我可以保留一个参考的方式,然后我可以重用一个对象?我尝试了使用导航器的各种方法,但是由于预先设置问题,这些方法都在一个iframe中失败。

例如:

navigator.stuff = 5;

只要在顶级窗口中完成,就可以正常工作。但如果我这样做:

警告(navigator.stuff);

在一个孩子的iframe中,我得到''undefined''...几乎就像
以为我是在引用一个不同的导航器
对象(??)。是什么赋予了?


您指的是另一个 - 导航器 - 对象。每个

全局/窗口对象都有自己的 - navigator - 对象,每个

窗口/框架/ iframe都有自己的全局/窗口对象(相互关联

通过 - top - 和 - parent - 引用和 - frames -

集合。

此外,如果我然后尝试引用而不是
top .navigator或者parent.navigator,我得到了许可被拒绝的错误,可能是因为我的iframe来自与其父级不同的URL。


跨域安全限制。如果你在不同的子域工作,你可以绕过它们但是如果想要在实际域中编写脚本,那么你就是在浪费时间(除非结果用于

一个内联网,你可以指定浏览器的安全设置。)

必须有一些偷偷摸摸的卑鄙的做法
这个


究竟做什么?解释实际要求(即回答

问题:为什么?),并详细说明。

(使用隐藏的框架可能?),
Does anybody know of a way that I can keep a reference
to an object that I can then reuse? I tried various
approaches using navigator, but these all fail in an
iframe due to premission problems.

For e.g.:

navigator.stuff = 5;

will work fine so long as this is done in the top level
window. But if I then do:

alert(navigator.stuff);

in a child iframe, i get ''undefined''... almost as
thought I were refering to a different navigator
object (??). What gives?
You are referring to a different - navigator - object. Each
global/window object has its own - navigator - object and each
window/frame/iframe has its own global/window object (interrelated
through the - top - and - parent - references and the - frames -
collection).
Furthermore, if I then try refering instead to
top.navigator or parent.navigator, I get permission denied
errors, presumably due to the fact that my iframe is coming
from a different URL than its parent.
Cross-domain security restrictions. You can get around them if you are
working in different sub-domains but if the desire is to script across
actual domains then you are wasting your time (unless the result is for
an Intranet and you can dictate browser security settings).
There must be some sneaky underhanded way of doing
this
Doing what exactly? Explain the actual requirement (i.e. answer the
question: why?), and in detail.
(using a hidden frame maybe?),



< snip>

如果跨域安全问题是另一个框架不太可能是b
解决方案因为它只能属于到一个域名本身。


理查德。


<snip>

If cross-domain security is the problem another frame is unlikely to be
the solution as it can only belong to one domain itself.

Richard.


这篇关于保持对对象的持久引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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