Click here to Skip to main content
15,896,478 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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
C#
namespace test
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            load_map();
        }
        void load_map()
        {
            // Load HTML document as a string
            Browser.IsScriptEnabled = true;
            Uri uri = new Uri("test2.html", UriKind.Relative);
            Stream stream = Application.GetResourceStream(uri).Stream;
            using (StreamReader reader = new StreamReader(stream))
            {
                // Navigate to HTML document string
                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
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

C#
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
Posted
Updated 13-Jun-12 23:55pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900