Im using the WebBrowser control to launch and browse some html files loaded locally in the windows phone 7 emulator and device. All works fine until a web page navigation with a query string us used. Th开发者_StackOverflow中文版e javascript needs to read these query strings but the navigation totally fails when the query string is included. The navigation works fine without the query string.
Im big time stuck on this and would really appreciate your thoughts. Tony
I too can't find a way to pass a query string to a local HTML file. (I copied the HTML file to Isolated Storage and viewed it from there.)
However...
I can successfully navigate to a local HTML file and specify a fragment. And it even works if the fragment includes equals signs (=) and ampersands (&) so you can do this:
webBrowser1.Navigate(new Uri("index.html#123=abc&456=def", UriKind.Relative));
And get the value with the following
<html>
<head>
<script type="text/javascript">
function onLoad() {
fs.innerHTML = document.location.href.split("#")[1];
}
</script>
</head>
<body onload="onLoad()" >
<p id="fs" />
</body>
</html>
to display the following on the page (in the browser control).
123=abc&456=def
(Obviously you could do something more appropriate with the value in javascript as necessary.)
Yes, you can just use the fragent like the querystring.
This, obviously, works fine as long as you don't need to use both.
You need a webserver if you pass a querystring.
This is because the browser does not know what is a query string in difference of another file. It only thinks the file is named "file.html?param=value" search this file and does not find it locally.
So locally without a webserver it is impossible.
Solutions
- Spawn a tiny webserver locally.
- Hack some js to know when it is local and replace all links with query string to hashtags
精彩评论