2

ある Web ページからユーザー入力を取得し、それを既に存在する別の Web ページに書き込もうとしています (問題がある場合はすべて同じドメイン内にあります)。JavaScript をデバッグし (以下を参照)、for ループを正しく反復し、書き込む正しい情報を構築することを確認しましたが、それが他の Web ページに書き込まれません。何が間違っているのかわかりませんが、助けていただければ幸いです。

listitem='';

function newHTML() {

     for (i=0;i<3;i++) {
          cc=document.forms['mainform'].list[i];
          if (cc.checked) listitem+=cc.value;
     }
     HTMLstring='<HTML>\n';
     HTMLstring+='<HEAD>\n';
     HTMLstring+='<TITLE>TESTING</TITLE>\n';
     HTMLstring+='</HEAD>\n';
     HTMLstring+='<BODY bgColor="blue">\n';
     HTMLstring+='"'+listitem+'"\n';
     HTMLstring+='< /BODY>\n';
     HTMLstring+='< /HTML>';
     alert(HTMLstring);
     newwindow=window.open('writeToThisPage.html');

     newwindow.document.write(HTMLstring);
     newwindow.document.close();

     window.open('writeToThisPage.html');
}
4

3 に答える 3

2

ここにデモがあります。そして、あなたは使用を避けるべきですdocument.write()

//open a new window
//"newWindow" is your reference to it
var newWindow = window.open();

//"newWindow.document.body" is the body of the new window
var newWindowBody = newWindow.document.body

//let's test by adding a text node to it
var text = document.createTextNode('foo');
newWindowBody.appendChild(text);​
于 2012-04-20T05:28:41.947 に答える
0

これはあなたが探しているものです:PI希望!!!

     HTMLstring='<HTML>\n';
     HTMLstring+='<HEAD>\n';
     HTMLstring+='<TITLE>TESTING</TITLE>\n';
     HTMLstring+='</HEAD>\n';
     HTMLstring+='<BODY bgColor="green">\n';
     HTMLstring+="<p>NinaMoxa</p>\n";
     HTMLstring+="<a href=\"javascript:self.close()\">Cerrar</a>\n";
     HTMLstring+='< /BODY>\n';
     HTMLstring+='< /HTML>';
     alert(HTMLstring);


     var ventana=window.open('','name','height=400,width=500'); 
     ventana.document.write(HTMLstring);
     ventana.document.close();

JNEによる

于 2012-04-20T05:41:28.757 に答える
0

1つのことを除いて、すべて問題ないようです。新しいドキュメントを作成した直後に、同じウィンドウを再度開いています。この最後の行をそのままにしておきます。

window.open('writeToThisPage.html');
于 2012-04-20T07:39:51.707 に答える