×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Issues working with web browser control

    Hi All,

    I am working on this new Lumia app where I have to get the html loaded document in my web browser control, filter html elements tags based on some criteria and validate user input.
    Parse html document include search for some tags, autofill text boxes values or validate user input values, automatically call submit button etc.

    here Html File will be dynamically loaded on my web browser control and I have no information about it.

    We can do this very easily with old control -
    Example is -

    webBrowser.Document.GetElementsByTagName(“div”);
    or
    webBrowser.Document.GetElementById(attribName).GetAttribute(“Value”);


    If we have to do same in windows phone what are alternatives -

    We can do something like this -
    String title = (string)browserCntrl.InvokeScript("eval", "document.title.toString()");

    It will give us title of document but how can be achieve the above in example with new web browser control.

    Is eval is the only approach to work with html document on new browser control?

    I am seeking for ideas and work around here.

    Thanks to all
    Last edited by sunder.tinwar; 2013-03-22 at 07:01.

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    297

    Re: Issues working with web browser control

    Hello,

    Just do a simple request using WebClient or HttpWebRequest using the "DownloadStringAsync("http://yoururl")" method, you will get a the html document as a string.

    then after you'll have to parse it, I use "htmlagility" api which allows you to parse your html very easily (you can download it from nuget).

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Thanks for reply, please check my updated question.

    I have to use web browser control only, as I have to work with user input, validate etc. So download string or http web request stuff will now work as per requirement.

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2012
    Posts
    88

    Re: Issues working with web browser control

    Hello,
    If I understand well what you're asking, you want to get and parse the current HTML content of your webbrowser control ?
    Did you try using the WebBrowser.SaveToString Method?
    As for Parsing, you can use HTMLAgility, it is very powerful and easy to use.

    Hope this helps,
    Charaf

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: Issues working with web browser control

    Is that working for you?

    You're running outside the browser and the web page and web site. The party that should be worried about injection is the site developers/owners.

    I think you will have an harder time parsing yourself the HTML than using that approach.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Yes all the examples provided here are working.

    We can parse a html document easily as shown in example. But I have to do same with new web browser control in windows phone sdk.

  7. #7
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Thanks for reply.

    We can save html page using WebBrowser.SaveToString Method. But then we have to parse it step by step.

    We will not be filter like this -
    webBrowser.Document.GetElementsByTagName(“div”);
    or
    webBrowser.Document.GetElementById(attribName).GetAttribute(“Value”);

    I have to use web browser control, as what user input I need to validate that and perform some action accordingly.

    I will dig into HTMLAgility today.

  8. #8
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Guys have anyone found any solution to this issue?

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    573

    Re: Issues working with web browser control

    Quote Originally Posted by sunder.tinwar View Post
    Guys have anyone found any solution to this issue?
    webBrowser.InvokeScript( ... ) is the only way to interact with the HTML document. It's not as convenient webBrowser.Document.GetElementsByTagName(“div”) but it's all we have - and this applies to both Windows Phone 7 and Windows Phone 8.

  10. #10
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    So is there a way we can achieve this webBrowser.Document.GetElementsByTagName(“div”) using webBrowser.InvokeScript( ... ). InovkeScript mostly useful in condition we know some js function already exits and we can just invoke it.

  11. #11
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: Issues working with web browser control

    You can count on eval being there.

  12. #12
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    HTMLAgility is supported till windows phone 7 and 7.5. Their library yet not support WP8. But I must say its very powerful tool for parsing html. Thanks for introducing this to me. I will keep looking into the issue and find a solution.

  13. #13
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Hi All, as we know its kind of difficult to achieve webBrowser.Document.GetElementsByTagName(“div”); with new web browser control, i tried to hack a bit here.

    What I did is, I wrote a generic javascript and try to inject that in loaded html page and reloaded the page again.

    But even when I am calling the javascript function from C# its throwing error. This is how I am working -
    webBrowserCntrl.InvokeScript("UpdatePageControls"); same error even if I call it will eval
    webBrowserCntrl.InvokeScript("eval","UpdatePageControls");

    and the error is An unknown error has occurred. Error: 80020006

    Even a simple test javascript function with just alert is throwing same above error.


    guys suggest a work around? Is the approach I am trying here is good and will work?

  14. #14
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Quote Originally Posted by sunder.tinwar View Post
    Hi All, as we know its kind of difficult to achieve webBrowser.Document.GetElementsByTagName(“div”); with new web browser control, i tried to hack a bit here.

    What I did is, I wrote a generic javascript and try to inject that in loaded html page and reloaded the page again.

    But even when I am calling the javascript function from C# its throwing error. This is how I am working -
    webBrowserCntrl.InvokeScript("UpdatePageControls"); same error even if I call it will eval
    webBrowserCntrl.InvokeScript("eval","UpdatePageControls");

    and the error is An unknown error has occurred. Error: 80020006

    Even a simple test javascript function with just alert is throwing same above error.


    guys suggest a work around? Is the approach I am trying here is good and will work?
    I think I have kind of resolved this issue and made it work. Still have some small issue. I will update the forum and post a solution.

    Is this approach is fine? I guess until we have output everything is fine...

  15. #15
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Hi Guys, I have resolved the issue I guess.

    we can interact with javascript using c# is via calling InvokeScript function where we will be knowing about javascript function already.

    And we can pass a value from javascript to c# via calling window.external.notify(variable);.

    But in my case I will never be knowing about html page.

    So its clear, write a generic javascript code and insert in html page and reload the page again. We can always get html page using WebBrowser.SaveToString(). Now we will be having an html page where we know some javascript function present which is according to our requirement.

    Just invoke the script on html page via calling javascript method and call another javascript method to retrieve value back from javascript function to C# code.

    So issue is resolved, got values from html page dynamically.

    Happy coding

Similar Threads

  1. Browser control issues, 100% CPU on processing
    By digitalsol in forum Symbian
    Replies: 5
    Last Post: 2010-11-02, 13:40
  2. Replies: 5
    Last Post: 2010-08-17, 10:34
  3. Browser Control LoadUrlL not working
    By saha_forumnokia in forum Symbian
    Replies: 3
    Last Post: 2007-12-26, 18:18
  4. S60 Browser Control/Plugin APIs issues
    By moranski in forum Symbian
    Replies: 5
    Last Post: 2007-10-17, 06:49
  5. S60 Browser Control/Plugin APIs issues
    By moranski in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2006-04-23, 09:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×