IE 中拒绝访问(同一域!)

发布于 2024-10-30 14:52:22 字数 523 浏览 7 评论 0原文

我知道 IE 存在跨站点脚本问题,但这是来自同一服务器/域。 (我实际上是使用 IP 地址访问服务器...但我认为这不可能是问题?)

问题是,我正在尝试使用 jquery.translate 翻译应用程序。在 FF(惊喜!)中,这就像一种魅力。但在 IE 中,我遇到了可怕的“访问被拒绝”错误。这是我所做的调用:

$(top.frames["Content"].document).translate('english');

我在框架的加载中执行此操作。现在是真正奇怪的部分:当我第一次加载框架集时它可以工作!但是当我单击框架右侧的链接时,我收到错误。 更奇怪的是:在框架的左侧,我放置了一个按钮,它将触发完全相同的代码 - 然后它就可以工作了!

当然,我认为该事件可能触发得太早了;在右框架完成加载之前。但即使我等了 10 秒,10 秒后 - 繁荣,我得到了错误......

我这里的头发已经用完了......:-) 有人有线索吗?

谢谢!

保罗

I know about the cross-site-scripting problems with IE, but this is comming from the same server/domain. (I'm actually access the server with a IP adres... but I think that cannot be the problem?)

The thing is, I'm trying to translate a application with jquery.translate. In FF (surprise!) this is working like a charm. But in IE I get the dreaded 'Access Denied' error. This is the call I do:

$(top.frames["Content"].document).translate('english');

I'm doing this in the onload of the frame. And now for the really strange part: when I load the frameset for the first time it works! But when I click on links in the right-part of the frame, I get the error.
Even stranger: in the left part of the frame I've put a button, that will fire the exact same code - and then it works!

Of course, I thought that the event might fire too soon; before the right frame has finished loading. But even when I wait 10 seconds, after 10 seconds - boom, I get the error....

I'm running out of hair here.. :-)
Anybody got a clue?

thanks!

Paul

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷途知返 2024-11-06 14:52:22

当我尝试访问 iframe 中的函数时,我遇到了同样的错误,这两个文档都来自同一域。我访问 iframe 的窗口对象及其函数的技术是这样的:

// if id for the iframe element is 'context', first make sure 
// it's accessible as a property of the main window object
if(! window.context ) window.context = window.frames[0] || null;
if( window.context === null ) alert("The Context screen is not available");

// grab a function from the iframe window and assign to var
var fadeLoader = window.context.fadeLoader; // this is an error in IE

...所以在我尝试调用该函数之前,我收到了引用它的错误。在 F12 控制台中进行操作,效果如下:

// grab a function from the iframe window and assign to var
var fadeLoader = window.context.window.fadeLoader; 
// now I can call the function
fadeLoader();

...但是现在,我在 Firefox 中收到错误,因为“window”不是 FF 中 iframe 元素的有效属性。相反,FF 使用(正确)contentWindow。因此,要使此功能全面工作:

if(! window.context ) window.context = window.frames[0] || null;
if(! window.context.window ) window.context.window = window.context.contentWindow;
var fadeLoader = window.context.window.fadeLoader;
fadeLoader();

似乎可以在 IE、FireFox、Chrome 和 Safari 中工作。

I was getting the same error when trying to access functions in an iframe, both documents originating from the same domain. My technique for accessing the iframe's window object and it's functions was along these lines:

// if id for the iframe element is 'context', first make sure 
// it's accessible as a property of the main window object
if(! window.context ) window.context = window.frames[0] || null;
if( window.context === null ) alert("The Context screen is not available");

// grab a function from the iframe window and assign to var
var fadeLoader = window.context.fadeLoader; // this is an error in IE

...so before I even can try calling the function, I get an error for referencing it. Playing around in F12 console, here's what worked:

// grab a function from the iframe window and assign to var
var fadeLoader = window.context.window.fadeLoader; 
// now I can call the function
fadeLoader();

...but now, I get an error in Firefox because 'window' is not valid property of an iframe element in FF. Instead FF uses (correctly) contentWindow. So, to make this work all around:

if(! window.context ) window.context = window.frames[0] || null;
if(! window.context.window ) window.context.window = window.context.contentWindow;
var fadeLoader = window.context.window.fadeLoader;
fadeLoader();

Seems to work in IE, FireFox, Chrome and Safari.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文