Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Browser plug-in to interact with browser

Thread view: 
DKM - 25 May 2005 21:10 GMT
Hello, I am trying to find out if it is possible to create browser
plug-in using java. The plug-in should have access to the browser's DOM
and shoud be able to dynamically alter content and style of any element
by responding to mouse movement and clicks anywhere on the browser
document.

I am new to all this, but I am familiar with javescript and html. And,
currently, I can achieve what I want using just javascript. But, I
would like to encapsulate all the javascript code in a java plug-in.

What technology is this called? I have been looking at some examples
from Sun's site and a few other sites, but I notice that the applet
occupies a certain area in the browser and the applet is only in
control of that particular area. I want the applet to have access to
all the tags in the page and be able to alter things line innerHTML,
style and such of any tag anywhere in the page. I believe that if
javascript can do all that an imbedded java applet should be able to do
that.

Thanks very much in advance.

D.K. Mishra
Andrew Thompson - 26 May 2005 03:34 GMT
> Hello, I am trying to find out if it is possible to create browser
> plug-in using java. The plug-in should have access to the browser's DOM
[quoted text clipped - 5 lines]
> currently, I can achieve what I want using just javascript. But, I
> would like to encapsulate all the javascript code in a java plug-in.

LiveConnect allows Java and JS to interact.  The most common way
to achieve what you want is to have the Applet communicate via
LiveConnect to the JS that directly interacts with/changes the DOM.

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

DKM - 26 May 2005 13:24 GMT
> > Hello, I am trying to find out if it is possible to create browser
> > plug-in using java. The plug-in should have access to the browser's DOM
[quoted text clipped - 11 lines]
>
> HTH

Thank you for the above info. Will this work in Netscape, Internet
Explorer and Mozilla browsers?

Thank you again in advance.

D.K. Mishra

> --
> Andrew Thompson
> http://www.PhySci.org/codes/  Web & IT Help
> http://www.PhySci.org/  Open-source software suite
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
Andrew Thompson - 26 May 2005 13:42 GMT
JS <-> Applet (connected via LiveConnect) to manipulate DOM.

> Will this work in Netscape, Internet
> Explorer and Mozilla browsers?

I do not know.  Try it and report back.

[ That also depends upon whether you can even get the JS to
work across the chosen browsers - no easy feat. ]

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

DKM - 26 May 2005 15:01 GMT
> JS <-> Applet (connected via LiveConnect) to manipulate DOM.
>
[quoted text clipped - 5 lines]
> [ That also depends upon whether you can even get the JS to
> work across the chosen browsers - no easy feat. ]

I have it working in IE and Firefox using only javascript. But, I know
what you mean, I had to dig into the dom of both the browsers to
understand what is implemented and what is not and determine the common
denominator.

As for reporting back on utilizing Liveconnect, that may take a while.
I have to learn an enormous amount before I start coding for the
browser plug-in.

Do you know of any simple example of a browser plug-in written in Java
that does a simple thing like changing the color or text of any
element.

Thank you very much in advance.

D.K. Mishra

> --
> Andrew Thompson
> http://www.PhySci.org/codes/  Web & IT Help
> http://www.PhySci.org/  Open-source software suite
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
Roland - 26 May 2005 15:54 GMT
>>JS <-> Applet (connected via LiveConnect) to manipulate DOM.
>>
[quoted text clipped - 22 lines]
>
> D.K. Mishra

<http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/java_js.html>

Example getting & setting document.cookie:
<http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thre
ad/fd6babade3625f00/e439ae0ba5b5b81f
>

Signature

Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \

DKM - 26 May 2005 19:21 GMT
> >>JS <-> Applet (connected via LiveConnect) to manipulate DOM.
> >>
[quoted text clipped - 27 lines]
> Example getting & setting document.cookie:
> <http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thre
ad/fd6babade3625f00/e439ae0ba5b5b81f
>

That should do it. Thank you very much for the links, specially the one
with example at Google archives.

D.K. Mishra

> --
> Regards,
[quoted text clipped - 3 lines]
>   /__/ w_/ /__/
> /  \ /_/ /  \
DKM - 28 May 2005 04:39 GMT
> >>JS <-> Applet (connected via LiveConnect) to manipulate DOM.
> >>
[quoted text clipped - 27 lines]
> Example getting & setting document.cookie:
> <http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thre
ad/fd6babade3625f00/e439ae0ba5b5b81f
>

I installed JDK 1.4.2.8 in the directory e:\java. I found plugin.jar in
e:\java\jre\lib. I created the environment variable classpath and set
it to "e:\java\jre\lib". I also added "e:\java\bin" to the path
environment variable. I can verify that it has been set by doing the
following:

echo %classpath%

I copied the example and saved it as sgcookie.java and the acompanying
html file as demo.html.

Next, I tried to compile sgcookie.java by the following command:

javac sgcookie.java

it gives lot of error about JSObject. Aparently, it can't find
plugin.jar.

But, if I compile with the -classpath option as follows:

javac -classpath "e:\java\jre\lib\plugin.jar" sgcookie.java

it compiles just fine. The demo html works fine too.

My question is this, whats the point of creating the environment
variable classpath if the compiler can't locate the whatever jar file
it needs in the classpath.

Thanks in advance.

D.K. Mishra

> --
> Regards,
[quoted text clipped - 3 lines]
>   /__/ w_/ /__/
> /  \ /_/ /  \
Andrew Thompson - 29 May 2005 07:27 GMT
> whats the point of creating the environment
> variable classpath if the compiler can't locate the whatever jar file
> it needs in the classpath.

Long ago Sun gave advice on how to add jars and classes to the classpath.

For som years now they have been saying that was a bad idea and that you
should set paths at the time of compilation or execution.

Now that you have compiled the example, you can add it to the applet's
classpath using the 'archive' element of the <applet> tag.

(By the way.  Please trim the posts you are replying to, including
only what is necessary.)

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

DKM - 01 Jun 2005 18:50 GMT
> > whats the point of creating the environment
> > variable classpath if the compiler can't locate the whatever jar file
[quoted text clipped - 4 lines]
> For som years now they have been saying that was a bad idea and that you
> should set paths at the time of compilation or execution.

I have now found dozens of messages regarding 'classpath'. Also, I
picked up an used old book titled "Java in a Nutshell" that basically
covers most of the basics, good enough for a beginer like me. Also, I
have picked up several examples of java to javascript plug-ins. Most
are very basic, but they all help.

> Now that you have compiled the example, you can add it to the applet's
> classpath using the 'archive' element of the <applet> tag.

This I am not understanding. I think what you are saying is that I
could create a library of routines and save it as jar file that my
other modules can use.

> (By the way.  Please trim the posts you are replying to, including
> only what is necessary.)

I get burnt anyway I do. I suppose all new to usenet learn the hard
way.

Thanks again for all the help.

D.K. Mishra

> --
> Andrew Thompson
> http://www.PhySci.org/codes/  Web & IT Help
> http://www.PhySci.org/  Open-source software suite
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
Andrew Thompson - 02 Jun 2005 03:21 GMT
..
>> Now that you have compiled the example, you can add it to the applet's
>> classpath using the 'archive' element of the <applet> tag.
>
> This I am not understanding. I think what you are saying is that I
> could create a library of routines ..

'classes', which might contain methods (routines) - a 'jar' file, yes.

>..and save it as jar file that my other modules can use.

Yep.  
<http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/applet.html>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

DKM - 04 Jun 2005 17:52 GMT
> ..
> >> Now that you have compiled the example, you can add it to the applet's
[quoted text clipped - 4 lines]
>
> 'classes', which might contain methods (routines) - a 'jar' file, yes.

You are right. I was thinking in terms of C.

Before I start coding all the classes, I wanted to have clear ideas
about the JSObject, but I could not find as much details as I wanted. I
found out that there are member funtions like getMember, setMember,
call, eval and such. So far, call and eval seem to work the way I think
they work. But, I am not clear about getMember and setMember. For
example, the following works.

JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject)win.getMember("document");
JSObject myform = (JSObject)doc.getMember("formname");
JSObject mybutton = (JSObject)myform.getMember("buttonname");

But, the following does not work.

JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject)win.getMember("document");
JSObject mypara = (JSObject)doc.getMember("paraname");

The applet is at the end of the body as below.

<P NAME="paraname">Hello</P>
<FORM NAME="formname">
<INPUT NAME="buttonname" TYPE=button VALUE="Change">
</FORM>
<APPLET CODE=test.class NAME="test" WIDTH=1 HEIGHT=1
MAYSCRIPT></APPLET>

Thank you very much in advance.

D.K. Mishra

> >..and save it as jar file that my other modules can use.
>
[quoted text clipped - 9 lines]
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
Andrew Thompson - 05 Jun 2005 02:00 GMT
> Before I start coding all the classes, I wanted to have clear ideas
> about the JSObject, but I could not find as much details as I wanted.

I found a distinct and unnerving lack of documentation available for
the LiveConnect, the documentation* at Netscape is less than comprehensive.
* <http://wp.netscape.com/eng/mozilla/3.0/handbook/plugins/>

My take on LiveConnect is simple.  Use the eval() (..or whatever)
method that calls JS methods to do the real work.  E.G. If you
need a cookie, do the code as a JS method 'makeCookie()' then simply
'eval( makeCookie() )'.

Reasons for this.  
1) The LiveConnect jar can be reduced to just a couple of classes to
achieve this (a test recently gave me a jar that was under 4Kb!).
2) The lack of documentation on JS (especially in relation to JS
differences *between* browser) gives me uneasy feelings.
3) The differences between versions of JS used in browsers can be
sorted in JS itself, and the JS programmers have a lot of very robust
code (and great ideas like 'feature detection') for achieving that.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

DKM - 05 Jun 2005 04:21 GMT
> > Before I start coding all the classes, I wanted to have clear ideas
> > about the JSObject, but I could not find as much details as I wanted.
[quoted text clipped - 7 lines]
> need a cookie, do the code as a JS method 'makeCookie()' then simply
> 'eval( makeCookie() )'.

You are right. eval will do everything. But, I have figured out now how
getMember works.

> Reasons for this.
> 1) The LiveConnect jar can be reduced to just a couple of classes to
[quoted text clipped - 4 lines]
> sorted in JS itself, and the JS programmers have a lot of very robust
> code (and great ideas like 'feature detection') for achieving that.

Again, thank you for your above observation.

D.K. Mishra

> --
> Andrew Thompson
> http://www.PhySci.org/codes/  Web & IT Help
> http://www.PhySci.org/  Open-source software suite
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
DKM - 12 Jun 2005 03:11 GMT
> >>JS <-> Applet (connected via LiveConnect) to manipulate DOM.
> >>
[quoted text clipped - 27 lines]
> Example getting & setting document.cookie:
> <http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thre
ad/fd6babade3625f00/e439ae0ba5b5b81f
>

I have now looked at most of the available resources on LiveConnect and
I have been able to create an Applet that utilizes LiveConnect.
However, the applet is working fine in FireFox and IE, but is crashing
when I refresh the page or leave the page in IE. I am using Sun Java
plug-in 1.4 and have disabled MSJVM. I have provided the source files
for the java and html code in another message titled "LiveConnect
applet crashing on pagre reload, please help". Can you please spare a
few minutes to have a look at the code and let me know whats wrong with
it and how it can be fixed.

Thanks very much in advance.

D.K. Mishra

> --
> Regards,
[quoted text clipped - 3 lines]
>   /__/ w_/ /__/
> /  \ /_/ /  \
Andrew Thompson - 26 May 2005 17:00 GMT
> Do you know of any simple example of a browser plug-in written in Java
> that does a simple thing like changing the color or text of any
> element.

Not specifically.

Try to see it this way.  Most of the important work with the DOM
should be done by JS, and written in JS.  If your applet needs
to trigger that functionality, it should simply call a JS method
that encapsulates the relevant commands.

The reason I say that is that manipulating the browser DOM is
really the specialty of JS progammers, and you would be best
off asking them on the JS group..
<http://groups-beta.google.com/group/comp.lang.javascript>

[ I have seen some horrendous Javascript written by Java programmers,
and what's worse - they actually think they know what they are doing. ;) ]

In fact, most of your basic testing can be done with HTML buttons
and such pretending to be the applet.  Once you have figured how
to manipulate the DOM to your satisfaction, put the applet in to
control it all.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

DKM - 26 May 2005 19:26 GMT
> > Do you know of any simple example of a browser plug-in written in Java
> > that does a simple thing like changing the color or text of any
[quoted text clipped - 6 lines]
> to trigger that functionality, it should simply call a JS method
> that encapsulates the relevant commands.

I understand. I was just looking for a starting point because I am
completely new to all this.

I have now found such an example now posted here in this newsgroup.

Thank you again for the help and the direction.

D.K. Mishra

> The reason I say that is that manipulating the browser DOM is
> really the specialty of JS progammers, and you would be best
[quoted text clipped - 15 lines]
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
Andrew Thompson - 26 May 2005 19:52 GMT
> I have now found such an example now posted here in this newsgroup.

Yes.  I see Roland's prepared a good, solid example there.
It sounds like you are set to go.

> Thank you again for the help and the direction.

You're welcome.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.