Interacting with the Browser widget
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Interacting with the Browser widget
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?
e.g. select a text, then have a script copy that text and use it in a handler. Is that possible?
Kaveh
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Interacting with the Browser widget
[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)]
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".
[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
Last edited by [-hh] on Wed Jan 02, 2019 2:18 pm, edited 1 time in total.
shiftLock happens
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Interacting with the Browser widget
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?
Kaveh
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Interacting with the Browser widget
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
shiftLock happens
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Interacting with the Browser widget
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?
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?
Kaveh
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Interacting with the Browser widget
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.
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.
shiftLock happens
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Interacting with the Browser widget
Much appreciated. I will study the html events and pls do let me know if you manage to make a demo stack...
Kaveh
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Interacting with the Browser widget
Much appreciated, Hermann. I will study this closely...
Kaveh