在IE7中的window.open()之后权限被拒绝

ant*_*oft 1 javascript winforms internet-explorer-7

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

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

在Web应用程序中,我运行一些javascript来打开一个子窗口并用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();
Run Code Online (Sandbox Code Playgroud)

当我们在这个WinForms应用程序中运行Web应用程序(但不是在其自身或在另一个WinForms应用程序中)时,我们在指示的行处出现Javascript错误:

Line 0: Access denied
Run Code Online (Sandbox Code Playgroud)

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

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

nic*_*k_w 5

基于:

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

您遇到的问题是,打开的Url需要与打开它的页面位于同一个域中.据推测,空白的Url不会共享其创建者的域名.我写了几个快速测试网页并找到了

  1. 调用var reportWindow = window.open('', newTarget, features);导致访问被拒绝错误.
  2. 同样的事情 var reportWindow = window.open('http://google.com', newTarget, features);
  3. 但是在网站中打开另一个页面会进行渲染 var reportWindow = window.open('WebForm2.aspx', newTarget, features);

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

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();
Run Code Online (Sandbox Code Playgroud)