2010-12-14 4 views
1

그리고이 겉보기에 간단한 질문을 살펴 주셔서 감사합니다.HTML 윈도우 간 이동

시나리오는 다음과 같습니다. 웹 사이트 홈페이지가 'welcome.html'입니다. 여기에서 사용자는 URL 목록에서 선택할 수 있으며 URL을 클릭하면 간단한 Javascript 기능이 호출되어 새 창을 엽니 다.

사용자가 새로 열린 윈도우에서 작업을 완료하면 버튼을 클릭하여 Javascript 기능을 호출하여 홈페이지로 되돌리기를 원합니다. 너무 단순 해 보입니다.

그러나 Homepage Window가 열려 있으면이 페이지로 돌아가서 홈페이지를 표시하는 다른 새 창을 열지 않습니다. Homepage Window가 닫혀 있다면, 새로운 Window를 열어서 홈페이지를 표시하고 싶습니다.

나는 그것이 작동하도록 보이지 않을 수 있으므로 여기에 약간의 안내에 대해 매우 감사 할 것입니다.

감사

크리스

을 다른 사람이 말했듯이
+4

모든 종류의 창을 여는 UI는별로 친숙하지 않습니다. 다른 디자인을 고려해보십시오. – Oded

+0

창 이름을 추적하면이 작업을 수행 할 수 있습니다. 그러나 그것을하지 마십시오. 브라우저가 새 창을 표시하는 방법을 제어 할 수 없으며 창을 전혀 표시하지 않을 수도 있습니다 (대신 탭을 사용). 윈도우 포커스 정책을 많이 제어 할 수는 없습니다. 전반적으로 사람들을 위해 새로운 창을 많이 열어 보는 것은 좋지 않습니다. – Pointy

+2

그는 진실을 말하기 때문에 @Oded를 들어야합니다. –

답변

1

, 그것은 가장 큰 디자인이 아니다. 그러나 비즈니스 로직에서 새 창을 열어야하며이를 변경할 수있는 권한이 없다고 규정하는 과거의 시나리오를 실행했습니다. http://www.quirksmode.org/js/popup.html

를하지만 가능하면, 내가 다른 디자인을 고려할 것입니다 :

는 뾰족한 가장 큰 것은 열린 창을 추적하는 단지이며, 당신은 몇 가지 더 도움이 필요하면, 아마이 도움이 될 수 말했듯 (구현에 도움이 필요하면 여기로 질문하십시오.)

+0

감사합니다. 그리고 다른 모든 사람들, 당신의 생각에 감사드립니다. 나는 좋은 패턴이 아니라는 것을 알고 있지만 모든 내용을 동일한 Window로 보내기 전에 현재 구조를 정돈해야합니다. 나는 해결책을 개발했고 나 자신에 대한 대답으로 그것을 나눌 것이다. – Chris

1

그리고 의견을 공유하는 데 어려움을 겪은 모든 분들께 감사드립니다.

다음과 같은 자바 스크립트가 새 창 여는 데 사용되는 새 창으로 홈페이지에서 탐색 :

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 뒤에는 초점이 맞지 않았습니다.

새 창에는 '메뉴'버튼이 있습니다.

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'오류가 발생했습니다.

많은 읽기 끝에 나는 내가 할 수있는 한 오류를 간단하게 처리 할 수있는 오류를 제거 할 수 없다고 생각했습니다. 위 코드가 생성되었습니다.

이것은 치료법으로 작용하고 이것이 도움이되기를 바랍니다.