2016-12-22 16 views
0

window.open(...)を使用して小さなポップアップ参照ウィンドウを開き、名前を付けます。そのウィンドウに対して次のwindow.openが呼び出されると、正しく再利用されます。URLハッシュが変更されたときにwindow.openで開いた開いているウィンドウを更新します

function openHelp(hash) { 
    var helpWindow = window.open(location.protocol + "/help.aspx" + (hash ? "#" + hash : ""), "helpWindow", "width=750, height=600, resizable=1, scrollbars=1, location=0, directories=0, status=no, menubar=no, toolbar=no"); 
} 

それが正常に動作しない1ケースは、誰かがヘルプページのURLで開いて、ウィンドウを持っているときにのみ、ハッシュ変化(すなわち#jump-to-me)。ページのリロードだけで、ページが適切にハッシュに移動します。

開いているウィンドウを見つける方法は、URLが私たちが開いているものと一致することをチェックし、条件付きでwindow.location.refresh()を実行します。

+1

私はすばやいgoogleが私にこれら2つのスタックオーバーフローポストを与えてくれました。 http://stackoverflow.com/questions/4059179/refresh-child-window-from-parent-window and http://stackoverflow.com/questions/3090478/jquery-hashchange-event –

答えて

0

ほとんどの場合、hashchangeイベントの特定のウィンドウにイベントリスナーを追加するだけでした。

function openHelp(hash) { 
    var helpWindow = window.open(location.protocol + "/help.aspx" + (hash ? "#" + hash : ""), "helpWindow", "width=750, height=600, resizable=1, scrollbars=1, location=0, directories=0, status=no, menubar=no, toolbar=no"); 
    helpWindow.addEventListener("hashchange", function() { this.location.reload() }, false); 
} 
1

私がこの権利を得たら、これが始まります。

var extraWindow; 

function makeWindow(){ 
    extraWindow= window.open(/* .. */); 
} 

// this will reload the extra window that you just opened. 
function reloadWindow(){ 
    if(extraWindow){ 
    extraWindow.location.reload(); 
    } 
} 

makeWindow(); 

// reload the window when the hash changes or possibly change the page url based on this. 
window.addEventListener("hashchange", reloadWindow, false); 

これは良い答えを提供します。

+0

私は感謝し始めました! –

関連する問題