本文介绍了IE7中window.open()之后的权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个带有嵌入式IE控件的winforms应用程序.

We have a winforms application with an embedded IE control.

在此IE控件中,我们运行一个Web应用程序(我控制该Web应用程序,但不控制Winforms应用程序).

In this IE control, we run a web application (I control the web application but not the winforms application).

在Web应用程序中,我运行一些javascript打开一个子窗口并用HTML填充它:

In the web application, I run some javascript to open a sub-window and populate it with HTML:

    var features = "menubar=no,location=no,resizable,scrollbars,status=no,width=800,height=600,top=10,left=10";
    newTarget = "reportWin" + String ( Math.random () * 1000000000000 ).replace( /\./g ,"" );
    reportWindow = window.open('', newTarget, features);
    var d = reportWindow.document; // <-- Exception is thrown here
    d.open();
    d.write('<head>\r\n<title>\r\n...\r\n</title>\r\n</head>');
    d.write('<body style="height: 90%;">\r\n<table style="height: 100%; width: 100%;" border="0">\r\n<tr>\r\n<td align="center" valign="middle" style="text-align:center;">\r\n');
    d.write(...);
    d.close();

当我们在此WinForms应用程序中运行Web应用程序时(而不是单独运行,也未在另一个WinForms应用程序中运行),我们在指示的行上出现Javascript错误:

When we run the web application within this WinForms app (but not by itself nor in another WinForms app) we get a Javascript error at the indicated line:

Line 0: Access denied

关于为什么会发生或如何避免的任何想法?请注意,该窗口未打开URL.这只是一个空窗口.

Any ideas on why this could be happening or on how I could avoid it? Note that the window is not opening a URL; it's just an empty window.

在同一应用程序中,打开在相同域中具有指定URL的窗口确实可行.

From the same application, opening a window with a specified URL in the same domain does work.

推荐答案

基于:

  1. IE 6/7访问拒绝尝试访问弹出窗口.document
  2. http://thecodecave.com/2006/07/20/how-to-get-around-access-is-denied-in-a-windowopen-javascript-call/
  1. IE 6/7 Access Denied trying to access a popup window.document
  2. http://thecodecave.com/2006/07/20/how-to-get-around-access-is-denied-in-a-windowopen-javascript-call/

您遇到的问题是,正在打开的网址必须与正在打开的页面位于同一域中.假定空白网址不会共享其创建者的域.我写了几个快速测试网页,发现了

The problem you are having is that the Url being opened needs to be on the same domain as the page that is opening it. Presumably a blank Url will not share the domain of its creator. I wrote a couple of quick test web pages and found

  1. 呼叫var reportWindow = window.open('', newTarget, features);导致访问被拒绝错误.
  2. var reportWindow = window.open('http://google.com', newTarget, features);
  3. 相同
  4. 但是在该网站中打开另一个可以渲染的页面var reportWindow = window.open('WebForm2.aspx', newTarget, features);
  1. Calling var reportWindow = window.open('', newTarget, features); resulted in the access denied error.
  2. Same thing with var reportWindow = window.open('http://google.com', newTarget, features);
  3. But opening up another page in the site which does the rendering does work var reportWindow = window.open('WebForm2.aspx', newTarget, features);

最后一个弹出窗口,指向执行该代码的WebForm2.aspx:

This last one popped up a window pointing to WebForm2.aspx which executed this code:

window.document.open();
window.document.write('<head>\r\n<title>\r\n...\r\n</title>\r\n</head>');
window.document.write('test<body style="height: 90%;">\r\n<table style="height: 100%; width: 100%;" border="0">\r\n<tr>\r\n<td align="center" valign="middle" style="text-align:center;">\r\n');
window.document.close();

这篇关于IE7中window.open()之后的权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:25