问题
Does anyone know how to pass a url parameter to a local page in the Web Browser Control?
When you navigate to the page alone "/Html/MyPage.html"
all is well but as soon as you add a parameter "/Html/MyPage.html?Message=Hello"
I get an error page stating that we could not navigate to the page.
Any ideas?
回答1:
As another workaround you can pass your arguments as location hash parameter (if it is not used)
browser.Navigate(new Uri("www/index.html#p=123&p2=567", UriKind.Relative));
and then in index.html
var args = window.location.hash;
(args = '#p=123&p2=567')
Tested on WP7 (index.html is stored in isolated storage) + WP8 (index.html is loaded directly from XAP)
回答2:
As a dirty workaround that just works you can implement this as following:
A. Navigate to the page w/o any parameters
B. Attach arguments passing logic below to one of the following events
WebBrowser.Navigated Event - when successfully navigated
WebBrowser.LoadCompleted Event - occurs after the WebBrowser control has loaded content.
C. Inject arguments to html page using webBrowser.InvokeScript (C#)
webBrowser.InvokeScript("eval", new string[] {"processArgs('someArgs') or any generated/custom script"});
or
webBrowser.InvokeScript("processArgs", new string[] {"someArgs"});
where processArgs is defined somewhere in your html file.
来源:https://stackoverflow.com/questions/13577114/how-to-pass-a-parameter-to-a-local-html-page-in-wp7-wp8