Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Browser/Javascript Communication
Browser/Javascript Communication [message #466305] Fri, 06 January 2006 07:35 Go to next message
Ivan Lazarte is currently offline Ivan LazarteFriend
Messages: 3
Registered: July 2009
Junior Member
After some looking, I see that the only way to communicate from the html
back to Java is this little trick:

boolean result = browser.execute("window.status=[javascript query here];");
...
and then get the text of the status.

I'm interested in embedding a javascript-based editor that will be working
with a lot of text. At some point I need to persist the information, so
I'd like to pass it back to Java to save in some manner. It doesn't seem
to me that depending on status being able to hold that information is
safe, especially with browsers constantly undergoing security revisions.

Has anyone found an alternate way to pass information about the html back
to Java?
Re: Browser/Javascript Communication [message #466327 is a reply to message #466305] Fri, 06 January 2006 16:21 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
Unfortunately, I don't think there is a way since the Browser instance is totally separate from the Java code. As far as the html knows, it's running in a full-fledge browser. In other words, there's no way for the JavaScript code to get any sort of reference to the Java code that its browser is embedded within.

I think your solution is pretty sound. I suggest that you profile your code a bit and find out how expensive the Browser#execute method is on average. If it isn't too bad, then set up an infinite loop (well, with an escape clause for stoppage) using Display#asyncExec(Runnable) to post to the event loop a call to the execute method. Depending on how expensive the call is, you could set a time delay on the loop (loop once, freeze for a quarter of a second, loop again). Hopefully the call isn't so expensive that you have to have a long delay (thus worse response time for the JavaScript editor persistance).
Re: Browser/Javascript Communication [message #466365 is a reply to message #466327] Mon, 09 January 2006 14:50 Go to previous messageGo to next message
Pierre Padovani is currently offline Pierre PadovaniFriend
Messages: 6
Registered: July 2009
Junior Member
Daniel Spiewak wrote:
> Unfortunately, I don't think there is a way since the Browser instance is totally separate from the Java code. As far as the html knows, it's running in a full-fledge browser. In other words, there's no way for the JavaScript code to get any sort of reference to the Java code that its browser is embedded within.
>
> I think your solution is pretty sound. I suggest that you profile your code a bit and find out how expensive the Browser#execute method is on average. If it isn't too bad, then set up an infinite loop (well, with an escape clause for stoppage) using Display#asyncExec(Runnable) to post to the event loop a call to the execute method. Depending on how expensive the call is, you could set a time delay on the loop (loop once, freeze for a quarter of a second, loop again). Hopefully the call isn't so expensive that you have to have a long delay (thus worse response time for the JavaScript editor persistance).

As I understand it, certain javascript engines allow for exensions to be
added to their runtimes. Could we not create an eclipse javascript
extension that allows javascript to perform calls out to eclispe? Does
the IE engine allow extensions? Does Mozilla's?

Just a thought.
Re: Browser/Javascript Communication [message #466442 is a reply to message #466365] Tue, 10 January 2006 15:34 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
Honestly, I'm not sure how feasible this is. You can probably do it in Mozilla because the entire mozilla engine is just one big Javascript runtime. IE is notoriously bad as far as Javascript compliance goes. You might be able to do it, but you would spend most of your time trying to make your code work both on IE and on Mozilla. Probably possible, just very very difficult.
Re: Browser/Javascript Communication [message #466715 is a reply to message #466305] Mon, 16 January 2006 05:14 Go to previous message
Adrian Baker is currently offline Adrian BakerFriend
Messages: 1
Registered: July 2009
Junior Member
Ivan wrote:
> After some looking, I see that the only way to communicate from the html
> back to Java is this little trick:
> boolean result = browser.execute("window.status=[javascript query here];");
> ..
> and then get the text of the status.
>
> I'm interested in embedding a javascript-based editor that will be
> working with a lot of text. At some point I need to persist the
> information, so I'd like to pass it back to Java to save in some
> manner. It doesn't seem to me that depending on status being able to
> hold that information is safe, especially with browsers constantly
> undergoing security revisions.
> Has anyone found an alternate way to pass information about the html
> back to Java?
>

You could make your (Java) application listen for a HTTP POST, then make your embedded browser post to it with a submit button on the html form.
Previous Topic:[ANN] SWTPlus, custom widgets for SWT
Next Topic:Providing Scrollbars
Goto Forum:
  


Current Time: Thu Mar 28 20:43:12 GMT 2024

Powered by FUDForum. Page generated in 0.03272 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top