How to scroll the contents of a <webview> tag using JavaScript?

I use a tag <webview>to embed a page. <webview>It has shadow-root, which has one tag <object id="browser-plugin-1 ...>. So I tried to set the value scrollTopfor this tag like this.

var webView = document.getElementById('webview tag id');
var elm = webView.shadowRoot.firstChild; // elm is object tag
console.log(elm.scrollTop);  // 0
elm.scrollTop = 100;
console.log(elm.scrollTop);  // 0

But nothing happened ...
Is it possible to control the scroll position of the tag <webview>outside?

+4
source share
2 answers

Yes, do this instead:

var webView = document.getElementById('webview tag id');
webView.executeJavaScript("document.querySelector('body:first-child').scrollTop=100");
+3
source

javascript WebView.executeJavaScript(code), WebView.

, WebView, javascript.

var webView = document.getElementById('webView');
webView.addEventListener('did-finish-load', scrollElement );

function scrollElement(){
    var code = "var elm = document.querySelector('body:first-child'); elm.scrollTop = 100;";
    webView.executeJavaScript(code);
}

. , .

( - AtomShell)

0

Source: https://habr.com/ru/post/1569409/


All Articles