2012-10-23 2 views
1

WebView 컨트롤에 문제가 있습니다. Windows 8 Metro Style app을 개발 중이며 WebView의 내용에서 스크립트를 호출하려고하지만 항상 빈 문자열을 반환합니다.WebView.InvokeScript는 항상 빈 문자열을 반환합니다.

"WebView.InvokeScript ("eval ", new string [] {"document.getElementById ('contentDiv') .officeHeight "})를 만들려고했으나 동일한 빈 문자열을 사용합니다. 난 정말 무엇을 잘못 어떤 추측은 여기에 없다가

public void Sethtml(string html) { 
      var toSet = string.Format(Style, html); 
      wv.LoadCompleted += wv_LoadCompleted; 
      wv.NavigateToString(toSet); 

     } 

void wv_LoadCompleted(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e) 
     { 
      WebView wv = sender as WebView; 
      string height = wv.InvokeScript("heightFun", new string[0]); 
     } 
public static readonly string Style = @"<!DOCTYPE html> 
               <html> 
               <head> 
               <title></title> 
               <style> 
               body {{ 
               font-family: Segoe UI; 
               }} 
               </style> 
               <script type='text/javascript'> 
               var heightFun = function() {{ 
                return document.getElementById('contentDiv').offsetHeight; 
               }} 
               </script> 
               </head> 

               <body> 
                <div id='contentDiv'> 
                 {0} 
                </div> 
               </body>"; 

답변

2

당신은 다시 값을 보낼 window.external.notify을 사용해야합니다 이 포럼 게시물을 참조하십시오.. http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/ac390a6a-d4ad-408c-8b13-93f9694cbabe

+0

simmilar 문제가있는 사용자 - javascript에서 변수를 전달하려는 경우 .toString() 메소드를 호출해야합니다. 그렇지 않으면 예외가 발생합니다. window.external.notify에서 반환 된 값은 WebView.ScriptNotify 이벤트 처리기에서 가져올 수 있습니다. 답으로 표시. – TrN

2

그냥 이전의 힌트를 통해이 문제를 해결 대답.

반환 값이 문자열인지 확인하십시오.

+0

고마워요! 나는이 일로 머리를 파고 들었다. 번호를 반환하려고 시도하고 myNumber.toString()이 트릭을 수행했습니다. – Reinaldo

관련 문제