Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I scroll content of <webview> tag from JavaScript?

  • atom-shell: https://github.com/atom/atom-shell
  • version: v0.20.2

I am using <webview> tag to embed a page. <webview> tag has shadow-root which has one tag, <object id="browser-plugin-1 ...>. So I tried to set scrollTop value for 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 happend...
Is it possible to control <webview> tag scroll position from outside?

like image 732
snufkon Avatar asked Dec 30 '14 10:12

snufkon


1 Answers

Yes, do this instead:

var webView = document.getElementById('webview tag id');
webView.executeJavaScript("document.querySelector('body:first-child').scrollTop=100");
like image 71
Ana Betts Avatar answered Oct 13 '22 15:10

Ana Betts