Any way to hide elements from webview? (android)

前端 未结 3 2000
孤城傲影
孤城傲影 2020-12-09 11:24

There\'s a webpage I pull up with webview, however i\'d like to hide the 1 text link at the top. Is there a way to do this? The link is in the body, so I can\'t hide the bod

3条回答
  •  不思量自难忘°
    2020-12-09 11:35

    I got it! By injecting javascript I had to use

    webview.loadUrl("javascript:(function() { " + "document.getElementsByTagName('a')[0].style.display = 'none'; " + "})()");

    That removes the link ( code). Replacing ('a') with ('img') would remove the images.

    (thanks lexanderA - Injecting JavaScript into a WebView )

提交回复
热议问题