簡體   English   中英

在Webview Android中僅顯示網站的一部分

[英]Displaying Only part of website in webview Android

我只想在我的Android WebView中顯示某些網站的特定部分。 我幾乎在線瀏覽了所有可用的解決方案,但無法實現我想要的。

我使用了Jsoup和HTML Cleaner,它可以正確顯示,但是頁面的CSS和JavaScript丟失了。

試圖在通過WebViewClient的onPageFinished中使用JavaScript,仍然一無所獲。

例如,如果我顯示https://gaana.com,那么我只想顯示頁面中位於的這一部分

我在onPageFinshed中有下面的代碼無法正常工作,如果我在這里缺少任何細微的東西,請告訴我。 `wb.setWebViewClient(new WebViewClient(){

        @Override
        public void onPageFinished(WebView view, String url)
        {
            webView.loadUrl("javascript:(function() { " +
"document.getElementById('Gaana-Home-Top_Ads').style.display='none'; " +

"document.getElementByClassName('breadcrum').style.display='none'; " +

"document.getElementByClassName('activeonscroll').style.display='none'; " +
"document.getElementByClassName('lastend-container').style.display='none'; " 
+

"document.getElementByClassName('mobile_search').style.display='none'; " +
"document.getElementByClassName('mobile-playlist-option').style.display='none'; " +

"document.getElementByClassName('bodyloader').style.display='none'; " +
"document.getElementById('mp').style.display='none'; " +
"document.getElementByClassName('Gaana_ROS_ATF_728adunit').
 style.display='none'; " 
 +

"document.getElementById('ads_645x60_pd_high').style.display='none'; " +
"document.getElementById('language-form').style.display='none'; " +


                    "})()");

        }
    });
    webView.loadUrl(URL);` .

任何幫助,將不勝感激。 謝謝。

您是否嘗試@media規則? (調整屏幕大小以查看示例)

 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { background-color: yellow; } @media only screen and (max-width: 600px) { body { background-color: lightblue; } } </style> </head> <body> <h1>The @media Rule</h1> <p>Resize the browser window. When the width of this document is 600 pixels or less, the background-color is "lightblue", otherwise it is "yellow".</p> </body> </html> 

使用此規則,如果使用Webview的訪問始終來自手機,則可以在智能手機上運行應用程序時獲取它。

詳情請參閱https://www.w3schools.com/cssref/css3_pr_mediaquery.asp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM