IE9“权限被拒绝”在由不再存在的框架创建的 xml 文档上

发布于 2024-11-24 06:27:10 字数 2173 浏览 1 评论 0原文

我遇到了一个非常奇怪的情况。我有以下设置:

父窗口有一个对象“bar”,其中包括 xml 文档和一些其他属性:

<html>
<head>
<script type="text/javascript">
var foo=null; //used in most report pages
var bar=function(document, boo){
    this.doc=document;
    this.boo=boo;
    this.baz="serge";
};
</script>
<head>  
<body>
    <iframe src="_child1.html"></iframe>
</body>
</html>

第一个子框架通过 ajax 加载一个简单的 xml 文件:

<html>
<head>
<script src="../lib/jquery.min.js"></script>
<script type="text/javascript">
$.ajax({
        url: "books.xml",
        type: "get",
        dataType: "xml",        
        success: function(data) {
            var boo = {
                name: "boo"
            };
            parent.foo = new parent.bar(data, boo);         
            alert(parent.foo.boo.name);
            alert(parent.foo.baz);
            alert(parent.foo.doc.firstChild.nodeName);
            window.location = "_child2.html";
        }
    });
</script>
</head>

<body>
    child1
</body>
</html>

XML 是:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
    Vaidyanathan Nagarajan
</bookstore>

成功时,它会在父窗口并将其存储在“foo”变量中,该变量再次驻留在父窗口中。

然后它输出这些属性(成功)并重定向到第二个子框架。

第二个子框架尝试访问父框架中的“foo”对象并输出其属性:

<html>
<head>
<script src="../lib/jquery.min.js"></script>
<script type="text/javascript">
alert(parent.foo.boo.name);
alert(parent.foo.baz);
alert(parent.foo.doc.firstChild.nodeName);
</script>
</head>

<body>
    child2
</body>
</html>

现在有趣的事情发生了: 在 FF 和 Chrome 中,我们看到 3 个属性触发了两次:一次在 _child1 中,第二次在 _child2 中。然而,在 IE9 中,我们只看到 5 个警报!

其原因是 parent.foo.doc 由于某种原因抛出“权限被拒绝”。

我相信原因是 IE 以某种方式“记住”xml 文档是在第一个子框架中创建的(可能是出于性能原因),并且当第二个子框架尝试访问该对象时 IE 无法找到它(或将其存储在受限内存堆栈中)。

此外,当我尝试这种情况时重定向 - 只需将这两个子框架放在父框架中 - 第二个子框架在访问父框架的 xml 文档时没有问题。

一种解决方法可能是在分配之前将这些 xml 文档克隆到“父级”中,但是我们有很多这样的场景,首先我想问是否有人有更好的主意?

谢谢。

I came into a really strange situation. I have the following setup:

Parent window has an object "bar" which includes an xml document and few other properties:

<html>
<head>
<script type="text/javascript">
var foo=null; //used in most report pages
var bar=function(document, boo){
    this.doc=document;
    this.boo=boo;
    this.baz="serge";
};
</script>
<head>  
<body>
    <iframe src="_child1.html"></iframe>
</body>
</html>

First child frame loads a simple xml file by ajax:

<html>
<head>
<script src="../lib/jquery.min.js"></script>
<script type="text/javascript">
$.ajax({
        url: "books.xml",
        type: "get",
        dataType: "xml",        
        success: function(data) {
            var boo = {
                name: "boo"
            };
            parent.foo = new parent.bar(data, boo);         
            alert(parent.foo.boo.name);
            alert(parent.foo.baz);
            alert(parent.foo.doc.firstChild.nodeName);
            window.location = "_child2.html";
        }
    });
</script>
</head>

<body>
    child1
</body>
</html>

The XML is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
    Vaidyanathan Nagarajan
</bookstore>

On success it creates a "bar" instance in the parent window and stores it in the "foo" variable which again resides in the parent window.

Then it outputs those properties (successfully) and redirects to a second child frame.

Second child frame tries to access the "foo" object in the parent frame and output its properties:

<html>
<head>
<script src="../lib/jquery.min.js"></script>
<script type="text/javascript">
alert(parent.foo.boo.name);
alert(parent.foo.baz);
alert(parent.foo.doc.firstChild.nodeName);
</script>
</head>

<body>
    child2
</body>
</html>

And now the interesting stuff happens:
in FF and Chrome we see the 3 properties fire two times: once in _child1 and secondly in _child2. In IE9 however, we see only 5 alerts!

And the reason for this is that parent.foo.doc throws "Permission denied" for some reason.

I believe that the reason is that somehow IE "remembers" that the xml document was created in the first child frame (perhaps for performance reasons) and when the second child frame tries to access that object IE isn't able to find it (or stores it in a restricted memory stack).

Furthermore, when I tried this scenario without redirecting - just putting those two child frames in the parent frame together - the second child frame had no problem accessing the parents' xml doc.

One workaround could be to clone those xml documents inside the "parents" before assigning, but we have many scenarios like this and first I would like to ask whether someone has a better idea?

Thanks.

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

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

发布评论

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

评论(2

寻找我们的幸福 2024-12-01 06:27:13

一旦单独的页面被垃圾收集,Internet Explorer 绝对不会允许您使用在单独页面中分配的 JavaScript 对象。您可以传递原始值,但我在帧之间传递“日期”实例时遇到了问题(很久以前,但仍然如此)。

您可以采用的一个技巧是调用父页面中的函数来根据原始值创建对象:

// in parent:

function newBar(what, ever) {
  return new bar(what, ever);
}

// in the frame page:

parent.foo = parent.newBar("what", "ever");

我认为这将使您免受问题的困扰,因为该对象将使用对象构造函数进行分配父页面,而不是框架页面中的页面。在以前的生活中,我开发的应用程序是一个庞大的、庞大的东西,涉及无数的 iframe(用于对话框、警告、各种东西)。我一直遇到这个问题,而且保持东西干净已经够痛苦的了,所以我发誓不再使用 iframe 来处理这类事情。

Internet Explorer will absolutely not let you get away with using a JavaScript object allocated in a separate page once that separate page has been garbage-collected. You can pass primitive values, but I've had problems (a long long time ago, but still) with "Date" instances passed between frames.

A trick you can pull is to call a function in the parent page to create your object from primitive values:

// in parent:

function newBar(what, ever) {
  return new bar(what, ever);
}

// in the frame page:

parent.foo = parent.newBar("what", "ever");

I think that'll insulate you from problems, because the object will be allocated with the Object constructor on the parent page, and not the one in the frame page. In a former life the application I worked on was a vast sprawling thing involving a zillion iframes (for dialogs, warnings, all sorts of stuff). I had this problem all the time, and keeping things clean was painful enough that I've sworn off using iframes for that kind of stuff.

我的痛♀有谁懂 2024-12-01 06:27:13

只是分享一个可以帮助其他人的替代解决方案。

由于 IE9 中对 iframe 对象的新处理,我的 Web 应用程序在 IE 9 中遇到权限被拒绝的问题(此处所述 http://msdn.microsoft.com/en-us/library/gg622929%28v=VS.85%29.aspx?ppud=4

对于我的情况,其中页面位于iframe(iframe A)被刷新,页面中存储的现有值被释放。当从另一个 iframe (iframe B) 进行 JavaScript 调用以访问 iframe A 中的对象时,出现“权限被拒绝”错误并且脚本停止执行。

最后我使用 javascript try catch 捕获错误并让脚本进一步运行而不是停止执行。

  try {
      var testObj = testObjArray['Object in iframe A'];
  } catch(err) {
      alert(err);
  }

希望这个替代解决方案可以帮助其他人。 :)

Just to share a alternative solution that could help others.

I was getting the permission denied issue in IE 9 for our web application due to the new handling for iframe object in IE9 (stated here http://msdn.microsoft.com/en-us/library/gg622929%28v=VS.85%29.aspx?ppud=4)

For my case where the page within an iframe (iframe A) was refreshed, existing value stored in the page was freed. When an javascript call was made from another iframe (iframe B) to access object in iframe A, it was getting "permission denied" error and script stop execution.

At last I use javascript try catch to capture the error and let the script to run further instead of stop execution.

  try {
      var testObj = testObjArray['Object in iframe A'];
  } catch(err) {
      alert(err);
  }

Hope this alternative solution can help others. :)

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