Javascript 在Windows10WebView中执行js脚本

Javascript 在Windows10WebView中执行js脚本,javascript,c#,win-universal-app,Javascript,C#,Win Universal App,我想运行一个js函数,该函数不写入加载的html页面,例如,我们有一个简单的html页面,带有按钮,我想使用外部js脚本禁用按钮: <!DOCTYPE html> <html> <body> <button id="my_button" type="button" onclick="">Click Me!</button> </body> </html> 如中

我想运行一个js函数,该函数不写入加载的html页面,例如,我们有一个简单的html页面,带有按钮,我想使用外部js脚本禁用按钮:

    <!DOCTYPE html>
    <html>
    <body>

    <button id="my_button" type="button" onclick="">Click Me!</button>

    </body>
    </html>
如中所述,有一个API方法
InvokeScriptAsync(string scriptName,string[]arguments)
,但我们必须已经将脚本加载到html页面中

任何建议都非常感谢

另外,在安卓系统中,我们的操作非常简单
webView.loadUrl(“我的脚本代码”)

您可以将InvokeScriptAsync与JavaScript eval函数一起使用,将内容注入网页

请参阅的“与WebView内容交互”部分

因此,要禁用该按钮,您可以在cs文件中使用以下代码:

String scriptStr = @"document.getElementById('your_buttonId').disabled=true";
await myWebView.InvokeScriptAsync("eval", new String[] {scriptStr});
String scriptStr = @"document.getElementById('your_buttonId').disabled=true";
await myWebView.InvokeScriptAsync("eval", new String[] {scriptStr});