2

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();

このWinFormsアプリ内で(ただし、単独でも別のWinFormsアプリでも)Webアプリケーションを実行すると、指定された行でJavascriptエラーが発生します。

Line 0: Access denied

なぜこれが起こる可能性があるのか​​、またはどうすればそれを回避できるのかについてのアイデアはありますか?ウィンドウがURLを開いていないことに注意してください。それはただの空のウィンドウです。

同じアプリケーションから、同じドメイン内の指定されたURLでウィンドウを開くことは機能します。

4

1 に答える 1

5

に基づく:

  1. IE6/7アクセスがポップアップwindow.documentにアクセスしようとして拒否されました
  2. http://thecodecave.com/2006/07/20/how-to-get-around-access-is-denied-in-a-windowopen-javascript-call/

あなたが抱えている問題は、開かれているURLがそれを開いているページと同じドメインにある必要があるということです。おそらく、空白のURLはその作成者のドメインを共有しません。私はいくつかの簡単なテストWebページを作成し、見つけました

  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この最後の1つは、このコードを実行したウィンドウをポップアップしました。

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();
于 2013-01-12T09:07:34.040 に答える