1

我有一个 WebBrowser (WinPhone C#),我在 CodeBehind 中设置了 NavigateToString。完整的代码在这里:

string f = "<!DOCTYPE HTML PUBLIC ' -//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><script type='text/javascript'>function get_radio_value(test){ var elements = document.getElementsByName(test); for (var i=0; i < elements.length; i++){if (elements[i].checked){var rad_val = elements[i].value;return rad_val;}}}</script><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1><form name='myForm' action=''><table border='2'><tr><td></td><td>sehr gut</td><td>gut</td><td>schlecht</td></tr><tr><td>Wie geht es Ihnen?</td><td><input type='radio' name='1' value='1'/>Mir ging es noch nie besser!</td><td><input type='radio' name='1' value='2'/>Es geht mir so wie immer.</td><td><input type='radio' name='1' value='3'/>Heute geht einfach gar nichts…&lt;/td></tr><tr><td>Können Sie Auto fahren?</td><td><input type='radio' name='2' value='1'/>Ja</td><td></td><td><input type='radio' name='2' value='3'/>Nein</td></tr><tr><td>Möchten Sie unseren Newsletter abonnieren?</td><td><input type='radio' name='3' value='1'/>Ja</td><td></td><td></td></tr></table></form></body></html>";
webbrowser.NavigateToString(f);

当我这样做时,WebBrowser 只显示代码而不是实际的 HTML 站点(带有 RadioButtons,...)。当我这样做时:

string f = "\"<!DOCTYPE HTML PUBLIC ' -//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><script type='text/javascript'>function get_radio_value(test){ var elements = document.getElementsByName(test); for (var i=0; i < elements.length; i++){if (elements[i].checked){var rad_val = elements[i].value;return rad_val;}}}</script><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1><form name='myForm' action=''><table border='2'><tr><td></td><td>sehr gut</td><td>gut</td><td>schlecht</td></tr><tr><td>Wie geht es Ihnen?</td><td><input type='radio' name='1' value='1'/>Mir ging es noch nie besser!</td><td><input type='radio' name='1' value='2'/>Es geht mir so wie immer.</td><td><input type='radio' name='1' value='3'/>Heute geht einfach gar nichts…&lt;/td></tr><tr><td>Können Sie Auto fahren?</td><td><input type='radio' name='2' value='1'/>Ja</td><td></td><td><input type='radio' name='2' value='3'/>Nein</td></tr><tr><td>Möchten Sie unseren Newsletter abonnieren?</td><td><input type='radio' name='3' value='1'/>Ja</td><td></td><td></td></tr></table></form></body></html>";
webbrowser.NavigateToString(f);

它正在工作!我只在开头设置了 \"。页面正在显示,但 " 就在我的网站顶部。为什么 f... 我必须在“html-file”的字符串开头写 \" 吗?

编辑:这个更短,但同样的问题:

不工作:

string f = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1>asdas</body></html>";
webbrowser.NavigateToString(f);

在职的:

string f = "\"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1>asdas</body></html>";
webbrowser.NavigateToString(f);
4

2 回答 2

1

我相信这是 WP8 中的一个错误,但有两种解决方法。一种方法是将 HTML 文件保存到隔离存储中,并使用WebBrowser.Navigate()打开 URI 的方法。如果您使用该方法,则无需修改 HTML 文件。

另一种方法是删除顶部 ( <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?>) 的声明,这样您的字符串将是

string f = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><script type='text/javascript'>function get_radio_value(test){ var elements = document.getElementsByName(test); for (var i=0; i < elements.length; i++){if (elements[i].checked){var rad_val = elements[i].value;return rad_val;}}}</script><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1><form name='myForm' action=''><table border='2'><tr><td></td><td>sehr gut</td><td>gut</td><td>schlecht</td></tr><tr><td>Wie geht es Ihnen?</td><td><input type='radio' name='1' value='1'/>Mir ging es noch nie besser!</td><td><input type='radio' name='1' value='2'/>Es geht mir so wie immer.</td><td><input type='radio' name='1' value='3'/>Heute geht einfach gar nichts…&lt;/td></tr><tr><td>Können Sie Auto fahren?</td><td><input type='radio' name='2' value='1'/>Ja</td><td></td><td><input type='radio' name='2' value='3'/>Nein</td></tr><tr><td>Möchten Sie unseren Newsletter abonnieren?</td><td><input type='radio' name='3' value='1'/>Ja</td><td></td><td></td></tr></table></form></body></html>";
webbrowser.NavigateToString(f);
于 2013-06-26T13:53:46.390 回答
0

我已经联系了微软。这是他们的答案:

来自 Microsoft Connect 的问候!

This notification was generated for feedback item: DOCTYPE not working in WP8 which you submitted at the Microsoft Connect site.

Thank you for submitting this Connect issue. The issue you reported appears to be on a released Windows Phone Product. As we only accept feedback on Visual Studio & .Net Framework through this site, we have notified the Windows Phone team and are closing this issue. If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com for assistance. To post a question or receive community support for developing Windows Phone apps, consider posting your question or concern on the Windows Phone Development forum. http://social.msdn.microsoft.com/Forums/en-us/category/wpapps.

You may receive a general "Feedback Item Updated" notification as well, if any other changes were made by Microsoft.

Thank you for using Microsoft Connect!

Regards,

the Microsoft Connect Team
于 2013-07-22T17:46:29.670 回答