How to pass a parameter to a local html page in WP

2019-02-18 13:39发布

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?

2条回答
对你真心纯属浪费
2楼-- · 2019-02-18 14:13

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-02-18 14:15

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)

查看更多
登录 后发表回答