Javascript IE7中window.open()后权限被拒绝
我们有一个带有嵌入式IE控件的winforms应用程序 在这个IE控件中,我们运行一个web应用程序(我控制web应用程序,但不控制winforms应用程序) 在web应用程序中,我运行一些javascript打开一个子窗口,并用HTML填充它:Javascript IE7中window.open()后权限被拒绝,javascript,winforms,internet-explorer-7,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
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();
关于为什么会发生这种情况,或者我如何避免这种情况,有什么想法吗?请注意,该窗口没有打开URL;只是一扇空窗户
从同一应用程序中,在同一域中打开具有指定URL的窗口确实有效。基于:
您遇到的问题是,正在打开的Url需要与正在打开它的页面位于同一个域中。可能一个空白Url不会共享其创建者的域。我写了两个快速测试网页,发现
var reportWindow=window.open(“”,newTarget,features)代码>导致访问被拒绝错误
var reportWindow=window.open('http://google.com",新目标,新特点),代码>
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();
window.document.open();
window.document.write('\r\n\r\n…\r\n\r\n');
window.document.write('test\r\n\r\n\r\n\r\n');
window.document.close();
您确定这不是正在运行的弹出窗口阻止程序吗?它看起来不是弹出窗口阻止程序,因为窗口确实打开了。问题是试图访问winodw中的文档对象。
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();