Reputation: 14786
We have a winforms application with an embedded IE control.
In this IE control, we run a web application (I control the web application but not the winforms application).
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();
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
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.
From the same application, opening a window with a specified URL in the same domain does work.
Upvotes: 2
Views: 15951
Reputation: 14938
Based on:
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
var reportWindow = window.open('', newTarget, features);
resulted in the access denied error.var reportWindow = window.open('http://google.com', newTarget, features);
var reportWindow = window.open('WebForm2.aspx', newTarget, features);
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();
Upvotes: 5