3

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?

Edward
  • 7,346
  • 8
  • 62
  • 123
  • http://stackoverflow.com/questions/4143383/wp7-pass-parameter-to-new-page That will help. – Tony Nov 27 '12 at 03:51
  • @Tony Thanks for the quick response. Actually I was referring to the Web Browser control with local HTML pages specifically rather than XAML pages. – Edward Nov 27 '12 at 03:52

2 Answers2

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.

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
Sergei Grebnov
  • 2,633
  • 18
  • 24
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)

Sergei Grebnov
  • 2,633
  • 18
  • 24