C#windows phone 8.1在WebView中调用成员

本文关键字:调用 成员 WebView phone C#windows | 更新日期: 2024-05-15 22:44:51

我有一个URL,里面有这个HTML代码

<html>
  <head>
    <title>Search</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  </head>
  <body>
  <form action="http://mySite.ir/search.html" method="POST">
  <input onkeypress=FKeyPress(this); onkeydown=FKeyDown(this); size="25" type="text" name="query" value=""/>
  <input type="submit" value="Search"/>
  </form>
</html>

我想在TextBox上放一些东西,然后按WebView上的ClickButton。在C#桌面中,我使用了这个代码>

webBrowser1.Document.GetElementById("textBoxV").SetAttribute("value", textBox1.Text);
webBrowser1.Document.GetElementById("pressButton").InvokeMember("submit");

但是在windowsphone 8.1中不能使用这种方法。请告诉我怎样才能按windows手机上的那个按钮?

C#windows phone 8.1在WebView中调用成员

您可以调用InvokeScriptAsync并在第一个表单(index==0)上调用submit,或者通过id获取表单,然后调用submit()。

await wview.InvokeScriptAsync("eval", new string[] { "var elem = document.forms[0].submit();"});

请确保HTML已加载到WebView中,否则会引发异常。