Failed to use web view with post parameters inmetro style app.
-
quarta-feira, 11 de julho de 2012 16:15
Hi All,
I am trying this sample code below in metro style app.:
string htmlFragment =
"<html><head><script type='text/javascript'>function SayGoodbye() { " +
"document.getElementById('myDiv').innerText = 'GoodBye'; } " +
"</script></head><body><div id='mydiv'>Hello</div></body></html>";
WebView3.NavigateToString(htmlFragment);
WebView3.InvokeScript("SayGoodbye", null);It is mentioned on MS link at:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview
it gives me the following exception:
{System.Exception: Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
at Windows.UI.Xaml.Controls.WebView.InvokeScript(String scriptName, String[] arguments)
at WebViewTest.MainPage.loadNewOffers() in e:\WebView\WebView\MainPage.xaml.cs:line 52}Please suggest what I am missing here?
My requirement is to send post parameters with requested URI using web view.
please suggest me if there is another way to achieve this in web view.
Thanks,
Metro
Todas as Respostas
-
quarta-feira, 11 de julho de 2012 16:54
Hi MyMetro,
It's just a typo in the MSDN doc... getElementById is case sensitive, and it's mixing myDiv and mydiv. Try correcting that.
"<html><head><script type='text/javascript'>function SayGoodbye() { " +
"document.getElementById('myDiv').innerText = 'GoodBye'; } " +
"</script></head><body><div id='myDiv'>Hello</div></body></html>";I'll file a bug on the MSDN doc so that this gets fixed online. Thanks for pointing it out!
Hope this helps,
Matt
XAML SDET Lead : Input / DirectManipulation / Accessibility
- Editado Matt GalbraithMicrosoft Employee quarta-feira, 11 de julho de 2012 16:59
-
quinta-feira, 12 de julho de 2012 05:38
Hi Matt
I tired your suggestion but it did not work as well.
I am getting the same error as before.
Please help me out.
Thanks,
Metro
-
quinta-feira, 12 de julho de 2012 16:45
Whoops, I corrected another bug while trying your repro without realizing it. Loading HTML, even a string, is an asynchronous task. You need to wait til LoadCompleted fires to call script methods. Try this please:
string htmlFragment = "<html><head><script type='text/javascript'>function SayGoodbye() { " + "document.getElementById('myDiv').innerText = 'GoodBye'; } " + "</script></head><body><div id='myDiv'>Hello</div></body></html>"; WebView3.LoadCompleted += WebView3_LoadCompleted; WebView3.NavigateToString(htmlFragment); ... void WebView3_LoadCompleted(object sender, NavigationEventArgs e) { WebView3.InvokeScript("SayGoodbye", null); }you can also use a ManualResetEvent or other tricks to continue execution after you call NavigateToSTring().
Hope this helps,
Matt
XAML SDET Lead : Input / DirectManipulation / Accessibility
- Editado Matt GalbraithMicrosoft Employee quinta-feira, 12 de julho de 2012 17:48 typo
- Marcado como Resposta MyMetro sexta-feira, 13 de julho de 2012 05:31
-
quinta-feira, 12 de julho de 2012 18:01
Whoops, I corrected another bug while trying your repro without realizing it. Loading HTML, even a string, is an asynchronous task. You need to wait til LoadCompleted fires to call script methods. Try this please:
string htmlFragment = "<html><head><script type='text/javascript'>function SayGoodbye() { " + "document.getElementById('myDiv').innerText = 'GoodBye'; } " + "</script></head><body><div id='myDiv'>Hello</div></body></html>"; WebView3.LoadCompleted += WebView3_LoadCompleted; WebView3.NavigateToString(htmlFragment); ... void WebView3_LoadCompleted(object sender, NavigationEventArgs e) { WebView3.InvokeScript("SayGoodbye", null); }you can also use a ManualResetEvent or other tricks to continue execution after you call NavigateToSTring().
Hope this helps,
Matt
XAML SDET Lead : Input / DirectManipulation / Accessibility
Thanks Matt,
It works for me.
Please asked to update it on MS link as well So other can also use it in correct manner.
Thanks a lot.
Thanks,
Metro
-
quinta-feira, 12 de julho de 2012 19:21
So I answer your question, then you mark your own post as Answer? Harsh.
XAML SDET Lead : Input / DirectManipulation / Accessibility
-
sexta-feira, 13 de julho de 2012 05:34
Hi Matt,
My mistake, Have rectified this. Thx again for your help.
Thanks,
Metro
-
terça-feira, 4 de setembro de 2012 12:10
This works for me too, thank you.Whoops, I corrected another bug while trying your repro without realizing it. Loading HTML, even a string, is an asynchronous task. You need to wait til LoadCompleted fires to call script methods. Try this please:
string htmlFragment = "<html><head><script type='text/javascript'>function SayGoodbye() { " + "document.getElementById('myDiv').innerText = 'GoodBye'; } " + "</script></head><body><div id='myDiv'>Hello</div></body></html>"; WebView3.LoadCompleted += WebView3_LoadCompleted; WebView3.NavigateToString(htmlFragment); ... void WebView3_LoadCompleted(object sender, NavigationEventArgs e) { WebView3.InvokeScript("SayGoodbye", null); }you can also use a ManualResetEvent or other tricks to continue execution after you call NavigateToSTring().
Hope this helps,
Matt
XAML SDET Lead : Input / DirectManipulation / Accessibility

