2012-05-28 3 views
0

웹 사이트를 입력 할 때 '추적 창'팝업 창을 구현하고 웹 사이트의 해당 창에 메시지를 보내 주문을 통해 더 어색한 문제를 진단합니다. 사이트와. 문제는 TraceText가 추가되기 전에 추적 창이 이미 존재하면 모든 내용이 제거 된 경우 페이지가 변경된다는 것입니다. 내가 원하는 것은 웹 사이트의 모든 페이지에서 메시지를 보낼 수있는 창입니다.팝업 창에 텍스트가 추가되지 않습니다.

저는 모든 스크립트 (아래 그림)에 스크립트로 포함 된 javascript 스크립트 debugger.js를 가지고 있는데, sendToTraceWindow() 함수를 호출하여 웹 사이트를 통해 메시지를 보냅니다. 이것은 현재 vbscript에서 주로 이루어지고 있는데, 나는 currenctly 조사하고있는 문제로 인해. traceWindow 변수 = null (아래 코드 참조)을 설정하는 모든 화면에 debugger.js에서 스크립팅하고 있기 때문에 생각합니다. 그러나이 문제를 해결하는 방법을 모르겠습니다!

도움을 주시면 감사하겠습니다. 앤드류

코드 예제 :

debugger.js :

var traceWindow = null 

function opentraceWindow() 
{ 
    traceWindow = window.open('traceWindow.asp','traceWindow','width=400,height=800') 
} 

function sendToTracewindow(sCaller, pMessage) 
{ 

    try 
    { 
     if (!traceWindow) 
     { 
     opentraceWindow() 
     } 

     if (!traceWindow.closed) 
     { 
     var currentTrace = traceWindow.document.getElementById('trace').value 
     var newTrace = sCaller + ":" + pMessage + "\n" + currentTrace 
     traceWindow.document.getElementById('trace').value = newTrace 
     } 
    } 
    catch(e) 
    { 
     var currentTrace = traceWindow.document.getElementById('trace').value 
     var newTrace = "error tracing:" + e.message + "\n" + currentTrace 
     traceWindow.document.getElementById('trace').value = newTrace 
    } 

} 

traceWindow.asp - ID = '추적'와 단지 텍스트 영역 :

<HTML> 
    <head> 
     <title>Debug Window</title> 
    </head> 
    <body> 
     <textarea id="trace" rows="50" cols="50"></textarea> 
    </body> 
</HTML> 
+0

다시 추적하려고합니까? 어떤 유형의 오류를 진단하려면? –

+0

Necesarily 오류는 아니지만 유용 할 수있는 모든 추적 :). 예를 들어, TraceWindow에 String 값인 sStatus가 주어진 순간에 표시되기를 원할 수 있으므로 sendToTraceWindow ("window_onmousemove", iStatus)를 호출하거나 누군가가 '저장'버튼을 누르면 로그인 할 수 있습니다. traceWindow sendToTraceWindow ("save_mouseup", "Save button pressed"). 그래서 오류가 아닙니다. 단지 버그를 찾는 데 유용 할 수있는 텍스트 일뿐입니다. –

답변

1

I traceWindow 변수가 재설정된다는 사실을 주위에 생각하지 마십시오. 모든 페이지를로드 할 때마다 기존 윈도우에 대한 핸들이 유효하지 않게됩니다. 그러나 LocalStorage 및 일부 jQuery를 사용하는 데 신경 쓰지 않는다면 원하는 기능을 얻을 수 있다고 생각합니다.

이에 추적 창을 변경

:

<html> 
    <head> 
     <title>Debug Window</title> 
     <script type="text/javascript" src="YOUR_PATH_TO/jQuery.js" /> 
     <script type="text/javascript" src="YOUR_PATH_TO/jStorage.js" /> 
     <script type="text/javascript" src="YOUR_PATH_TO/jquery.json-2.2.js" /> 
     <script type="text/javascript"> 
     var traceOutput; 
     var traceLines = []; 
     var localStorageKey = "traceStorage"; 

     $(function() { 
      // document.ready. 
      // Assign the trace textarea to the global handle. 
      traceOutput = $("#trace"); 
      // load any cached trace lines from local storage 
      if($.jStorage.get(localStorageKey, null) != null) { 
      // fill the lines array 
      traceLines = $.jStorage.get(localStorageKey); 
      // populate the textarea 
      traceOutput.val(traceLines.join("\n")); 
      } 
     }); 

     function AddToTrace(data) { 
      // append the new trace data to the textarea with a line break. 
      traceOutput.val(traceOutput.val() + "\n" + data); 
      // add the data to the lines array 
      traceLines[tracelines.length] = data; 
      // save to local storage 
      $.jStorage.set(localStorageKey, traceLines); 
     } 

     function ClearTrace() { 
      // empty the textarea 
      traceOutput.val(""); 
      // clear local storage 
      $.jStorage.deleteKey(localStorageKey); 
     } 
     </script> 
    </head> 
    <body> 
     <textarea id="trace" rows="50" cols="50"></textarea> 
    </body> 
</html> 

그런 다음 데이터를 추적하려는 페이지에, 당신은 다음처럼 자바 스크립트를 수정할 수 :

var traceWindow = null;     
function opentraceWindow() {      
    traceWindow = window.open('traceWindow.asp','traceWindow','width=400,height=800'); 
} 

function sendToTracewindow(sCaller, pMessage) { 
    traceWindow.AddToTrace(sCaller + ":" + pMessage); 
} 

때마다 새로운 페이지를 가로드되고 추적 창이 새로 고쳐지면 기존 추적 데이터가 로컬 저장소에서로드되고 텍스트 영역에 표시됩니다. 이것은 당신이 찾고있는 기능을 달성해야합니다.

모든 오류가 있으면 친절히 부탁드립니다. 월요일 아침에 날개를 달고 있습니다.

jQuery 라이브러리를 찾는 일은 쉽지 않습니다. jStorage 라이브러리는 http://www.jstorage.info/이고 여기에서 jquery-json을 찾을 수 있습니다. http://code.google.com/p/jquery-json/

+0

우수 감사합니다. 개발 환경에서 '켜기'만 할 것이므로 로컬 저장소에 아무런 문제가 없습니다. 좋은 해결책 같아. 나는 전에 jquery를 사용하지 않았다. 그래서 나는 그것을 줄 것이다! –

관련 문제