如何在Delphi中获取和设置TChromium滚动条位置?
发布于 2013-11-19 00:18:27
可以直接使用javascript对象。只要使用框架的CefV8Context即可。
下面是一个示例:
var
val: ICefV8Value;
context: ICefv8Context;
excp: ICefV8Exception;
scroll: TPoint;
begin
if (Chromium1.Browser.MainFrame = nil) then
exit;
//this will work only with exact frame
context := Chromium1.Browser.MainFrame.GetV8Context;
if (context <> nil) then
begin
context.Eval('window.pageXOffset', val, excp);
scroll.x := val.GetIntValue;
context.Eval('window.pageYOffset', val, excp);
scroll.y := val.GetIntValue;
end
else
exit;
//todo: do something with scroll here
end;发布于 2013-05-30 03:03:55
目前正在使用CefSharp,我确实认为这与在Delphi中类似。以下是我的解决方案:
public int GetVerticalScrollPosition()
{
var r = _webView.EvaluateScript(@"document.body.scrollTop");
return Convert.ToInt32(r);
}
public void SetVerticalScrollPosition(int pos)
{
_webView.ExecuteScript(
string.Format(@"document.body.scrollTop = {0}", pos));
}我不再是Delphi专家了,希望你能理解我的代码;基本上是通过EvaluateScript和ExecuteScript方法I use JavaScript to read/write the scroll positions并执行这些小的JavaScript代码片段。
发布于 2017-04-11 23:54:06
您需要在TCromium.Browser中使用JavaScript。这是最简单的方法:
Chromium1.Browser.MainFrame.ExecuteJavaScript('window.scrollBy(0,50)', 'about:blank', 0);祝好运!
https://stackoverflow.com/questions/13914065
复制相似问题