【发布时间】:2016-11-04 23:10:58
【问题描述】:
我正在尝试通过注入 Javascript 函数来更改 WebView(非本地)中已加载网站的 CSS。我找到了这两篇文章(Article 1,Article 2),但是在实现这两个版本之后,我总是得到以下异常: System.NotImplementedException {“方法或操作未实现。”}
到目前为止,这是我的代码:
MainPage.xml
...
<WebView x:Name="WebView" LoadCompleted="webViewCSS_LoadCompleted"/>
...
MainPage.xaml.cs
...
private void webViewCSS_LoadCompleted (object sender, NavigationEventArgs e)
{
addCss();
}
private void addCss()
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("function setCSS() { ");
sb.Append("document.getElementsByClassName('app')[0].style.width = '100%';");
sb.Append("} ");
string script = sb.ToString();
WebView.InvokeScript("eval", new string[] { script });
WebView.InvokeScript("eval", new string[] { "setCSS()" });
} catch (Exception ex)
{
}
}
...
我不知道它为什么会抛出异常。我希望我提供的信息已经足够了。如果没有,请回复我:-)
提前感谢您的回答
【问题讨论】:
标签: c# css webview uwp invokescript