2012-03-01 1 views
1

내 응용 프로그램에서 팝업 창을 통해 일부 데이터를 인쇄 중입니다. 팝업로드시 사용자에게 인쇄 또는 취소하라는 메시지가 표시됩니다. 클릭 한 버튼에 따라 어떤 조치를 취할 수 있도록 어떤 버튼이 클릭되었는지 (인쇄 또는 취소) 알고 싶습니다. 코드와 스크린 샷은 다음과 같습니다.웹 브라우저의 인쇄 팝업에서 클릭 (확인 또는 취소) 이벤트를 알 수있는 방법

public void Print(int Id) 
     { 
      StringBuilder sb = BadgeHelper.preparePrintableString(Id); 
      string printWindowFunc = "function printWindow() {\n" + 
             "var z = window.print();\n alert('Return: ' + z);\n" + 
             "checkDocumentState();\n" + 
             "}"; 
      string checkDocumentStateFunc = "function checkDocumentState() {\n" + 
               "if (document.readyState == 'complete') {\n" + 
                "window.close();\n" + 
               "}\n" + 
               "else {\n alert('Else');\n" + 
                "setTimeout('checkDocumentState()', 2000);\n" + 
               "}\n"+ 
              "}\n"; 

      string startingHTMLCode = "<html>\n" + 
             "<head>\n" + 
              "<script type='text/javascript'>\n " + 
               checkDocumentStateFunc + 
               "\n" + 
               printWindowFunc + 
              "</script>\n " + 
             "</head>\n" + 
             "<body onload='printWindow();'>\n"; 
      sb.Insert(0, startingHTMLCode); 
      sb.Append("\n</body>\n</html>"); 

      Response.Write(sb.ToString()); 
     } 

enter image description here

+0

확인이 : http://stackoverflow.com/questions/1692668/find-whether-save-or-cancel-button-is-clicked-on-print -dialog-box – ionden

+1

좋은 질문이지만, 이것이 1) '공정한'js 2)에서 가능하지 않다는 생각이 들기는합니다. (너무 똑똑하고 활동적인 인터페이스에 대한 제 개인적 증오입니다.) –

+0

'onbeforeprint/onafterprint'는 인쇄 상태를 확인하거나'window.print' 결과를 반환 할 수 없습니다. – kirilloid

답변

0

당신은 window.opener 기능을 사용하여 자바 스크립트에서 열리는 창에 액세스 할 수 있습니다.

http://www.w3schools.com/jsref/prop_win_opener.asp

그런 다음 (숨겨진 입력 말한다) 변수를 설정하거나 팝업을 연 창에 다시 게시를 강제로이를 사용할 수 있습니다. 파이어 폭스, 크롬 등과의 호환성에 대해서는 잘 모르겠지만 과거에는 그것을 사용 해왔다. 여기

비슷한 질문

JQuery - Write to opener window

관련 문제