Page 1 of 1

Interacting with the Browser widget

Posted: Thu Dec 27, 2018 5:15 pm
by kaveh1000
I am interested in copying text from a web site through the Browser widget. Any possibilities?

e.g. select a text, then have a script copy that text and use it in a handler. Is that possible?

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 1:35 pm
by [-hh]
[Repost because my first answer was partially wrong].

[Edit: If you use it with ordinary mouseDown or mouseUp the widget may loose focus (and the current text selection, especially in Safari-like browsers)]

Code: Select all

-- copies current text selection from a webpage displayed in the browser widget
on mouseDown b
  if b=3 then
    do "document.execCommand('copy');" in widget "browser"
    put the fullClipboardData["text"] into txt
    answer "Copied:" &cr &txt -- do something with txt
  end if
end mouseDown
If you have full control over the page you can get the innerHTML of a DOM element, for example from a textarea or an input element of type"text".

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 2:04 pm
by kaveh1000
Thanks for that. I have put this in a button, and I select text in the browser widget, but it is not copying that text. It uses what was in the clipboard before. Any ideas?

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 2:15 pm
by [-hh]
Use a method such that the widget doesn't loose focus: rightClick (or mouseEnter or ...).

Code: Select all

on mouseDown b
  if b=3 then
    do "document.execCommand('copy');" in widget "browser"
    put the fullClipboardData["text"] into txt
    answer "Copied:" &cr &txt -- do something with txt
  end if
end mouseDown

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 2:59 pm
by kaveh1000
Great. This is working now. :-)

So it seems there are no handlers like mouseWithin etc that a browser widget understands, right?

Is there any way we can sense remotely that a text has been selected by user? Perhaps test each 1 second and if the focus of the browser is true and text is selected then grab the text?

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 3:27 pm
by [-hh]
Add an event handler to your webpage that calls back to LC.
Then you get without anything more needed always a "notification" from the webpage, as soon as the user has selected some text, attached the selected text.

This isn't difficult but not a 5 minute job.
(5 minutes is the limit to answer posts in the forum or the list I set for me in 2018.)

Given time I'll make a demo-stack with this (and more) in subforum HTML5/Browser widget usage examples.

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 3:39 pm
by kaveh1000
Much appreciated. :-) I will study the html events and pls do let me know if you manage to make a demo stack...

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 9:09 pm
by [-hh]

Re: Interacting with the Browser widget

Posted: Wed Jan 02, 2019 9:25 pm
by kaveh1000
Much appreciated, Hermann. I will study this closely...