This case happened when i programming.
First, i have 2 pages: MainPage.xaml and Page1.xaml.
In Mainpage.xaml, I had a button for going to Page1 and a web browser load a html file.
Code Page1.xaml
namespace test
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
load_map();
}
void load_map()
{
Browser.IsScriptEnabled = true;
Uri uri = new Uri("test2.html", UriKind.Relative);
Stream stream = Application.GetResourceStream(uri).Stream;
using (StreamReader reader = new StreamReader(stream))
{
Browser.NavigateToString(reader.ReadToEnd());
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string msg = "";
if (NavigationContext.QueryString.TryGetValue("act", out msg))
{
string[] result = msg.Split('|');
string content_text = result[1];
switch (result[0])
{
case "1": load(content_text); break;
default: break;
}
}
}
void load(string text)
{
Browser.InvokeScript("load", text);
}
}
}
File HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="TM500" />
<title>Untitled 2</title>
</head>
<script type="text/javascript">
load(var1)
{
documents.writeln(var1);
}
</script>
<body>
hello world!!!
</body>
</html>
Code Page1.xaml
namespace test
{
public partial class Page1 : PhoneApplicationPage
{
public Page1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string adr = tb1.Text;
NavigationService.Navigate(new Uri("/MainPage.xaml?act=1|"+adr, UriKind.Relative));
}
}
}
When Mainpage.xaml get parameter from Page1.xaml then active javascript in html
load(var1). I got this error:
An unknown error has occurred. Error: 80020006.
I really don't know why.
Please someone help me.
P/S:
My project