1

I wish to show only the login-page element of a URL. My current approach which is not working:

web.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url)
            {
                view.loadUrl("javascript:document.getElementByClassName('login-page')");
            }
        });
        web.loadUrl("https://www.reddit.com/reddits/login");
Jake Lee
  • 7,549
  • 8
  • 45
  • 86
code
  • 11
  • 2

2 Answers2

0

For mobile screens you should develop separate screens and embed it.

Another way is if your web page supports p/# tag (i.e) like

https://developer.android.com/guide/components/fundamentals.html#Components

https://www.reddit.com/reddits#login this should navigate the page directly to login form

Anyhow I prefer you should develop the page for mobile screens.

Nandha
  • 128
  • 10
  • It's worth noting that even if you can load the page to a specific section, the user is either going to be able to scroll away, or you'll have to do an absurd amount of work to ensure only the right amount of the site is shown based on screen size etc. – Jake Lee May 14 '18 at 15:46
0

Your approach is close to working, but you should modify the existing page instead of trying to load a subset of the existing page as a new one.

The following hides elements with class SectionToRemove, you could instead hide all and only make visible the area you need:

@Override 
public void onPageFinished(final WebView view, String url) {
    super.onPageFinished(view, url);
    view.loadUrl("javascript:$('.SectionToRemove').hide();");
}

That being said, Reddit has extensive APIs that should be used if possible, this approach may breach Terms of Service.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86