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