Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Xamarin.Forms中删除WebView中网页的某些部分_Javascript_C#_Html_Webview_Xamarin.forms - Fatal编程技术网

Javascript 如何在Xamarin.Forms中删除WebView中网页的某些部分

Javascript 如何在Xamarin.Forms中删除WebView中网页的某些部分,javascript,c#,html,webview,xamarin.forms,Javascript,C#,Html,Webview,Xamarin.forms,在我的移动应用程序中,我正在使用WebView加载一个网站,如下所示 webBrowser1.Source = "https://overwatchleague.com/en-us/news/22482778/world-cup-bangkok-s-standout-players"; InitializeNewsPageAsync(); public async void InitializeNewsPageAsync() { webBrowser1.Navigated += as

在我的移动应用程序中,我正在使用
WebView
加载一个网站,如下所示

webBrowser1.Source = "https://overwatchleague.com/en-us/news/22482778/world-cup-bangkok-s-standout-players";
InitializeNewsPageAsync();


public async void InitializeNewsPageAsync()
{
    webBrowser1.Navigated += async (o, s) =>
    {
       await webBrowser1.EvaluateJavaScriptAsync(@"element.parentNode.removeChild(document.getElementById('Navbar is-compact is-auto is-custom-logo'));");
       await webBrowser1.EvaluateJavaScriptAsync(@"element.parentNode.removeChild(document.getElementById('c-Header js-header'));");
       await webBrowser1.EvaluateJavaScriptAsync(@"element.parentNode.removeChild(document.getElementById('u-verticalNavPadding'));");
       await webBrowser1.EvaluateJavaScriptAsync(@"element.parentNode.removeChild(document.getElementById('ContentModule ContentModule-background--white'));");
       await webBrowser1.EvaluateJavaScriptAsync(@"element.parentNode.removeChild(document.getElementById('BuyCTA'));");
       await webBrowser1.EvaluateJavaScriptAsync(@"element.parentNode.removeChild(document.getElementById('TexturedBackground TexturedBackground--dark'));");
       };
}
我想删除页面的某些部分,以便只能显示主要内容。就像智能手机浏览器中的阅读器一样。但是,无论是
webBrowser1.Eval()
还是
webBrowser1。EvaluateJavaScriptAsync()
工作正常。我还尝试了两种不同的Java脚本

document.getElementByClassName('Navbar is-compact is-auto is-custom-logo').style.display = 'none';

他们都没有工作。我只想显示div标签中的主要内容

<div class="u-horizontalPadding--medium" id="main-news-section"> ... </div>
。。。
我尝试过使用XPath和HtmlWebViewSource只加载div标记的内容,但只加载基本的HTML,而不加载CSS或JavaScript。在图片中,这就是我想要实现的目标

这就是没有操纵的页面的外观


从技术上讲,你可以这样做,但这几乎肯定违反了他们的TOS
<div class="u-horizontalPadding--medium" id="main-news-section"> ... </div>