Interacting with the Browser widget

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Interacting with the Browser widget

Post by kaveh1000 » Thu Dec 27, 2018 5:15 pm

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?
Kaveh

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Interacting with the Browser widget

Post by [-hh] » Wed Jan 02, 2019 1:35 pm

[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".
Last edited by [-hh] on Wed Jan 02, 2019 2:18 pm, edited 1 time in total.
shiftLock happens

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Interacting with the Browser widget

Post by kaveh1000 » Wed Jan 02, 2019 2:04 pm

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Interacting with the Browser widget

Post by [-hh] » Wed Jan 02, 2019 2:15 pm

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

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Interacting with the Browser widget

Post by kaveh1000 » Wed Jan 02, 2019 2:59 pm

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?
Kaveh

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Interacting with the Browser widget

Post by [-hh] » Wed Jan 02, 2019 3:27 pm

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.
shiftLock happens

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Interacting with the Browser widget

Post by kaveh1000 » Wed Jan 02, 2019 3:39 pm

Much appreciated. :-) I will study the html events and pls do let me know if you manage to make a demo stack...
Kaveh

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Interacting with the Browser widget

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

shiftLock happens

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Interacting with the Browser widget

Post by kaveh1000 » Wed Jan 02, 2019 9:25 pm

Much appreciated, Hermann. I will study this closely...
Kaveh

Post Reply

Return to “Talking LiveCode”