0

I am trying to get the full Html Source of the WebPage Loaded into the WebView and my Code is Working Fine But It's giving me null for One url( //mobile.twitter.com) While on Other pages of Twitter(like //mobile.twitter.com/account),it is working fine. But Give me an Error for the that One URl; My Code:

            twitter_WebView.addJavascriptInterface(new LoadListener(), "HTMLOUT");
            twitter_WebView.loadUrl("javascript:window.HTMLOUT.processHTML(document.documentElement.outerHTML); ");
     class LoadListener{
        @JavascriptInterface
        public void processHTML(String html) throws IOException
        {
            pageHTML = html; // Giving Me Null here ///
            })
  }
PjAndro
  • 3
  • 5
  • If the HTML element is missing, the return value of *document.documentElement.outerHTML* is null. – Rami Nov 25 '14 at 19:31
  • But Html Element is must for a Webpage( twitter is loaded in WebView) Ok,If I get Null Should I Do This: twitter_WebView.loadUrl("javascript:window.HTMLOUT.processHTML(''+document.getElementsByTagName('body')[0].innerHTML+'');); – PjAndro Nov 25 '14 at 19:34
  • Html element is for HTML documents, and WebView contain HTML code/document – Rami Nov 25 '14 at 19:38
  • Do you have any Alternate to get the Code that is being shown in the WebView ? – PjAndro Nov 25 '14 at 19:40
  • I don't have an idea how to resolve this problem, but i just mention you that *document.documentElement.outerHTML* return Null only if the HTML element is missing. To get the HTML from web view, try this http://stackoverflow.com/a/8201246/4224337 (i haven't tested it) – Rami Nov 25 '14 at 19:42
  • Thanks for that post but I have tried that one too. Even That One Works for Every Url But this. – PjAndro Nov 25 '14 at 19:44
  • Well I Found the Solution.You were Correct Maybe there was no HTMl Element.So I tried searching the Body Tag and get the Code .Thanks For Your Help Here – PjAndro Nov 25 '14 at 19:52

0 Answers0