java - Get and set focus position in SWT browser -


i want , set position within swt browser don't know how.

first, created browser control:

browser browser = new browser(shell, swt.none); 

then launched html document:

file file = new file("c:\\test\\index.html"); browser.seturl(file.touri().tostring()); 

that works perfect far. scroll down page find interesting text passage , click menu item create kind of bookmark. question is: how can current focus position (x,y) remember point in text , how can reset position later "apply" specific bookmark?

you can interact browser content through browser#evaluate() , browser#execute(). both methods allow execute javascript in context of browsers document.

to send javascript code queries current position, use like:

object position = browser.evaluate( "window.getcurrentposition();" ); 

the type of return value depends on code evaluated. debug through code see actual return type is.

if aren't interested in return value, use execute. example set current position use:

browser.evaluate( "window.setcurrentposition( x, y );" ); 

please note javascript pseudo-code , doesn't return current position.

if run swtexceptions, document isn't loaded yet , need delay execution of javascript code until loaded explained here: https://stackoverflow.com/a/7802717/2986905


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -