1

私は自分のjavascriptコードから開いたウィンドウを持っています:

 window.open('/Item/Article/' + item.ItemID(), 'ItemArticle', 
'resizable=yes,scrollbars=yes,height=' + res.height + ',width=' + res.width + ',
 left=0', null);

特定の条件が満たされたときに、そのウィンドウの html アドレスを変更したい、つまり新しい場所にリロードしたい。

手動で開いたウィンドウに ID またはアンカーを設定して、この ID を使用してそのウィンドウを新しい場所でリロードできるようにするにはどうすればよいですか。

4

4 に答える 4

1

1) ウィンドウへの参照を持ち、2) を使用するときに名前を述べる可能性がありますwindow.open()

var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);

同じウィンドウ名 (2 番目の引数) を選択することで、ウィンドウを変更できます。

var myWindow = window.open("http://google.com","myWindow");
// opens SO in the same window
window.open("http://stackoverflow.com","myWindow");
// the following will only work if it's the same domain, else subject to SOP -
// so in the case of initially opening it with google, this won't work!
myWindow.document.location.href = "/example/test.html";
// closes your window
myWindow.close();

したがって、あなたの場合、次の行が機能するはずです。

window.open('newURL','ItemArticle'/* optionally: ,'Parameters'*/);
于 2013-07-10T10:54:21.170 に答える
1

ウィンドウを変数に格納し、通常のウィンドウ オブジェクトを制御するのと同じように制御できます。

次のコードは新しいウィンドウを開き、4 秒後に新しい場所にリロードします。

myWindow=window.open('','','width=200,height=100');
myWindow.focus();
setTimeout(function(){
    myWindow.document.location = "http://www.google.com";
}, 4000);
于 2013-07-10T10:55:57.333 に答える
0

window.openウィンドウ A からウィンドウ B の URL を更新する場合は、2 番目の引数と同じ名前を指定して実行できます。これは、すでに開いているウィンドウを単純に「再度開き」、新しい URL にリダイレクトします。

window.open('http://www.google.com','googleWindow');
window.open('http://www.stackoverflow.com','googleWindow');

上記のコードは、Google でウィンドウを開き、即座に Stack Overflow にリダイレクトします。

ただし、これによりウィンドウが自動的にフォーカスされるかどうかは不明です!

于 2013-07-10T10:53:02.070 に答える
0

以下の方法を使用して、子ウィンドウが開かれた場所から親ウィンドウの機能にアクセスできます。

window.opener.ParentWindows(); //Here ParentWindows() is userdefined function coded by me in parent window

于 2013-07-10T10:54:29.477 に答える