2010-12-14 6 views
1

この一見単純な質問を見てくれてありがとう。HTMLウィンドウの間を移動

シナリオは次のとおりです。「welcome.html」という名前のWebサイトがあります。ここからユーザーはURLのリストから選択でき、URLをクリックすると新しいJavascript関数が呼び出され、新しいウィンドウが開きます。

新しく開いたウィンドウでユーザーが終了すると、Javascript機能を呼び出してホームページに戻すボタンをクリックします。それはとても簡単です。

しかし、Homepage Windowがまだ開いている場合、私はこれに戻り、Homepageを表示する別の新しいWindowを開きません。 Homepage Windowが閉じられている場合は、新しいWindowを開いてホームページを表示します。

私はそれが動作するように見えないので、私はここにいくつかの指導には非常に感謝します。

よろしく

クリス

を他の人が言ったように
+4

すべての種類のウィンドウを開くUIはあまり親切ではありません。異なるデザインを検討してください。 – Oded

+0

ウィンドウ名を追跡するだけでこれを行うことができます。しかし、しないでください。ブラウザが新しいウィンドウをどのように表示するかを制御することはできません。ウィンドウを表示する(タブを使用する、言い換えれば)こともできます。ウィンドウのフォーカスポリシーを制御することはできません。全体的には、人々のためにたくさんの新しいウィンドウを開くのは良い考えではありません。 – Pointy

+2

彼は真実を語っているので、@Odedを聞いてください。 –

答えて

1

は、それが最大のデザインではありません。しかし、私は過去にこのようなシナリオを実行しました。ビジネスロジックでは、新しいウィンドウを開く必要があり、そのウィンドウを変更する能力がないと規定されています。

とんがりは最大のものがちょうど開いたウィンドウを追跡することで、あなたはさらにいくつかの助けが必要な場合は、おそらくこれは役立つかもしれない、言ったように: http://www.quirksmode.org/js/popup.html

をしかし、可能であれば、私は別の設計を検討します(実装に手助けが必要な場合は、ここにお尋ねください)

+0

ありがとうございました、他の皆さん、あなたの考えに感謝します。私はそれが良いパターンではないことを知っているが、私はすべてのコンテンツを同じウィンドウに入れる前に、現在の構造を整理しなければならない。私は解決策を開発しました。私は自分自身への答えでそれを以下に共有します。 – Chris

1

あなたのご意見をお寄せいただき、ありがとうございました。

私は、以下の方法で問題を解決した:

を次のJavaScriptは、新しいウィンドウを開くために使用される新しいウィンドウにホームページから移動するとき:

function popupFull(url) 

// For explanation of this code see: http://www.quirksmode.org/js/popup.html 

// Note: If fullscreen = 1 you can't see the menubar, toolbar, status etc. 
// It is advisable to have no spaces around the commas in the parameters. 

{ 
    //alert("Opening: " + url) 

    // Prepare the parameter string 
    params = 'width='+screen.width; 
    params += ',height='+screen.height; 
    params += ',top=0,left=0'; 
    params += ',fullscreen=0'; 
    params += ',menubar=0'; 
    params += ',toolbar=0'; 
    params += ',directories=0'; 
    params += ',status=0'; 
    params += ',scrollbars=0'; 
    params += ',resizable=1'; 

    // Open a new window. 
    newWin=window.open(url, "fullWindow", params); 

    // If the current Window is in focus, switch focus to the new Window. 
    if (window.focus) 
    { 
     newWin.focus() 
    } 

    // Return the new Window object reference. 
    return newWin; 
} 

ので、新しいウィンドウをすることができ私はHomepage Windowを開いたままにしておきましたが、新しいWindowの背後にはフォーカスがありません。

新しいウィンドウには「メニュー」ボタンがあります。これをクリックすると、次のJavaScript関数を呼び出します。

function openMenu(winURL, winName, winFeatures) 
{ 
// Create a reference of the Window which opened this Window. This should be 
// the Main Menu Window. 
var winObj=window.opener; 

var menuOuterWidth = 1080; 
var menuOuterHeight = 896; 

var menuInnerWidth = 1068; 
var menuInnerHeight = 767; 

var menuX = (screen.width - menuOuterWidth)/2; 
var menuY = (screen.height - menuOuterHeight)/2; 

// Prepare the parameter string for re-opening the Menu 
params = 'width='+menuInnerWidth; 
params += ',height='+menuInnerHeight; 
params += ',top='+menuY+',left='+menuX; 
params += ',fullscreen=0'; 
params += ',menubar=1'; 
params += ',toolbar=1'; 
params += ',status=1'; 
params += ',scrollbars=1'; 
params += ',location=1'; 
params += ',resizable=1'; 

try 
{ 
    // Check to see if the window reference already exists. 
    if (winObj) 
    { 
     // Check to see if the Menu window is closed. 
     if (winObj.closed) 
     { 
      // The Menu window is closed. 
      // Open the Menu Window. 
      winObj = window.open(winURL, winName, params); 

      // Close this Course Window. 
      window.close(); 

      // Return the Menu Window object reference should the caller want it. 
      return winObj; 
     } 
     else 
     { 
      // The Menu Window has not been closed. Set the Window's size and position. 
      // Note: When resizing the outerWidth/outerHeight value has to be passed. 
      winObj.window.resizeTo(menuOuterWidth, menuOuterHeight); 
      winObj.window.moveTo(menuX, menuY); 

      // Bring it into focus (bring to front). 
      winObj.focus(); 

      // Close this Course Window. 
      window.close(); 

      // Return the Menu Window object reference should the caller want it. 
      return winObj; 
     } 
    } 

    else 

    { 

     // The winObj object does not exist. Open the Menu. 
     winObj = window.open(winURL, winName, params); 

     // Close this Course Window. 
     window.close(); 

     // Return the Menu Window object reference should the caller want it. 
     return winObj; 
    } 
} 

catch(err) 
{ 
    txt="There was an error on this page.\n\n"; 
    txt+="Error description: " + err.description + "\n\n"; 
    txt+="Click OK to continue.\n\n"; 
    //alert(txt); 

    // When IE6 tries to obtain the winObj.closed property, when the window is closed, it can cause 
    // an error "Permission Denied". This error is caught here. Open the Menu. 

    // Open the Menu Window. 
    winObj = window.open(winURL, winName, params); 

    // Close this Course Window. 
    window.close(); 

    // Return the Menu Window object reference should the caller want it. 
    return winObj; 
} 

}

コメントがすべてを説明する必要があります。キーは、開始したHomepage Windowへの参照を取得することです。 (var winObj=window.opener;)。

私は新しいウィンドウを開くと(IE6を使用して)ホームページに戻り、ホームページウィンドウを閉じた後、[メニュー]ボタンをクリックした新しいウィンドウで何も起こりませんでした。私はすべてを試した後、一杯のお茶の後に、私がエラーキャプチャの形式を使わずに開発していたアプリケーションにコードを書くことは決してないと気づきました。 Try、Catch文を追加し、エラーを「警告」に報告しました。 「Permission Denied」エラーが表示されます。

多くの読書の後、私はエラーを取り除くことができなかったと思ったので、私はできるだけエレガントにエラーを処理します。これで上記のコードが作成されました。

これは治療に役立ち、これが誰かを助けることを願っています。

関連する問題