WebView provides an InvokeScript method that executes the specified script function from the currently loaded HTML with specific arguments. When the WebView LoadCompleted event occurs, I call this JavaScript, which disables scrolling. Check all the code below.
string DisableScrollingJs = @"function RemoveScrolling() { var styleElement = document.createElement('style'); var styleText = 'body, html { overflow: hidden; }' var headElements = document.getElementsByTagName('head'); styleElement.type = 'text/css'; if (headElements.length == 1) { headElements[0].appendChild(styleElement); } else if (document.head) { document.head.appendChild(styleElement); } if (styleElement.styleSheet) { styleElement.styleSheet.cssText = styleText; } }"; void webView_LoadCompleted(object sender, NavigationEventArgs e) { webView.InvokeScript("eval", new[] { DisableScrollingJs }); }
From codeproject .
Thomas bouman
source share