简体   繁体   中英

javascript windows phone 7.1

i try to execute a javascript in Windows phone

IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();

            IsolatedStorageFileStream location = new IsolatedStorageFileStream(path,
                System.IO.FileMode.Open, file);
            HtmlDocument doc = new HtmlDocument();
            doc.Load(location);





            string newContent = "<script type='text/javascript'>"
                         + "function getSelectionHtml()"
                     + "{"
              + "var html = '';"
       +"if (typeof window.getSelection != 'undefined')" 
            +"{"
        +"var sel = window.getSelection();"
        +"if (sel.rangeCount)" 
        +"{"
           +" var container = document.createElement('div');"
            +"for (var i = 0, len = sel.rangeCount; i < len; ++i)" 
            +"{"
                +"container.appendChild(sel.getRangeAt(i).cloneContents());"
            +"}"
            +"html = container.innerHTML;"        
        +"}"
        +"}"
             + "elseif (typeof document.selection != 'undefined')"
                + "{"
               + "if (document.selection.type == 'Text')"
                + "{"
                + "html = document.selection.createRange().htmlText;"
               + "}"
                +"}"
               +"return Html;"
                + "}"
                  + "</script>";
                         HtmlNode newNode = HtmlNode.CreateNode(newContent);

            // Get body node
            HtmlNode body = doc.DocumentNode.SelectSingleNode("//head");

            // Add new node as first child of body
            body.PrependChild(newNode);
            savefile(doc);
            string path4 = "Cyrlej/Epub/The Motor/42461/@public@vhost@g@gutenberg@html@files@42461@42461-h@42461-h-0.htmcopie.html";
            MyWebBrowser.Navigate(new Uri(path4, UriKind.Relative));


public static void savefile(HtmlDocument file)
        {



       using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream isoStream =
                new IsolatedStorageFileStream("Cyrlej/Epub/The Motor/42461/@public@vhost@g@gutenberg@html@files@42461@42461-h@42461-h-0.htmcopie.html", FileMode.Create, isoStore))
            {

                file.Save(isoStream);
            }
        }

i successfully add the script to my html and now when i try to invoke the script by

MyWebBrowser.InvokeScript("getSelectionHtml");

alwayes i get error "Error: 80020006" any one have an idea thank you in advance

Perhaps you are trying to call a script when the page is not loaded. Try:

MyWebBrowser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(Browser_LoadCompleted);

void Browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
   MyWebBrowser.InvokeScript("getSelectionHtml");            
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM