currently in uwp app getting text-selection of webview through
datapackage package = await webview.captureselectedcontenttodatapackageasync(); and read out string
await package.getview().gettextasync(); this works on pc not on phone.
what best way go on phone? tried injecting javascript
window.getselection().tostring(); or document.selection.createrange().text; but didn't work or used wrong way.
any appreciated.
update1:
changed code following result still works on pc not on phone:
string texttoget = await mainwebview1.invokescriptasync("eval", new string[] { "document.getselection().tostring();" }); if (texttoget != null) { debug.writeline("text is: " + texttoget.tostring().trim()); } else { messagedialog msgbox3 = new messagedialog("please select or mark text get."); await msgbox3.showasync(); }
i use
string text = webview.invokescriptasync("eval", "document.getselection()"); remember you're working in browser @ point of getting selection await package.getview().gettextasync(); going wonky on different devices. above method leverages javascript should equal on each device.
Comments
Post a Comment