我有一个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…</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…</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文件”吗?
编辑:这个更短,但同样的问题:
不工作:
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);
答案 0 :(得分: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…</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);
答案 1 :(得分: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