Re: Browser plug-in to interact with browser

Discussion in 'Java' started by DKM, May 26, 2005.

  1. DKM

    DKM Guest

    Andrew Thompson wrote:
    > On 25 May 2005 13:10:22 -0700, DKM wrote:
    >
    > > 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.

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


    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
    DKM, May 26, 2005
    #1
    1. Advertising

  2. On 26 May 2005 05:24:37 -0700, DKM wrote:

    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. ]

    --
    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, May 26, 2005
    #2
    1. Advertising

  3. DKM

    DKM Guest

    Andrew Thompson wrote:
    > On 26 May 2005 05:24:37 -0700, DKM wrote:
    >
    > 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. ]


    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
    DKM, May 26, 2005
    #3
  4. DKM

    Roland Guest

    On 26-5-2005 16:01, DKM wrote:
    >
    > Andrew Thompson wrote:
    >
    >>On 26 May 2005 05:24:37 -0700, DKM wrote:
    >>
    >>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. ]

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


    <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/thread/fd6babade3625f00/e439ae0ba5b5b81f>

    --
    Regards,

    Roland de Ruiter
    ___ ___
    /__/ w_/ /__/
    / \ /_/ / \
    Roland, May 26, 2005
    #4
  5. On 26 May 2005 07:01:34 -0700, DKM wrote:

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

    --
    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, May 26, 2005
    #5
  6. DKM

    DKM Guest

    Roland wrote:
    > On 26-5-2005 16:01, DKM wrote:
    > >
    > > Andrew Thompson wrote:
    > >
    > >>On 26 May 2005 05:24:37 -0700, DKM wrote:
    > >>
    > >>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. ]

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

    >
    > <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/thread/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,
    >
    > Roland de Ruiter
    > ___ ___
    > /__/ w_/ /__/
    > / \ /_/ / \
    DKM, May 26, 2005
    #6
  7. DKM

    DKM Guest

    Andrew Thompson wrote:
    > On 26 May 2005 07:01:34 -0700, DKM wrote:
    >
    > > 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.


    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
    > 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.
    >
    > --
    > 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, May 26, 2005
    #7
  8. Andrew Thompson, May 26, 2005
    #8
  9. DKM

    DKM Guest

    Roland wrote:
    > On 26-5-2005 16:01, DKM wrote:
    > >
    > > Andrew Thompson wrote:
    > >
    > >>On 26 May 2005 05:24:37 -0700, DKM wrote:
    > >>
    > >>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. ]

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

    >
    > <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/thread/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,
    >
    > Roland de Ruiter
    > ___ ___
    > /__/ w_/ /__/
    > / \ /_/ / \
    DKM, May 28, 2005
    #9
  10. On 27 May 2005 20:39:54 -0700, DKM wrote:

    > 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.)

    --
    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, May 29, 2005
    #10
  11. DKM

    DKM Guest

    Andrew Thompson wrote:
    > On 27 May 2005 20:39:54 -0700, DKM wrote:
    >
    > > 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.


    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
    DKM, Jun 1, 2005
    #11
  12. On 1 Jun 2005 10:50:12 -0700, DKM wrote:

    > Andrew Thompson wrote:
    >> On 27 May 2005 20:39:54 -0700, DKM wrote:

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

    --
    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, Jun 2, 2005
    #12
  13. DKM

    DKM Guest

    Andrew Thompson wrote:
    > On 1 Jun 2005 10:50:12 -0700, DKM wrote:
    >
    > > Andrew Thompson wrote:
    > >> On 27 May 2005 20:39:54 -0700, DKM wrote:

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


    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.

    >
    > Yep.
    > <http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/applet.html>
    >
    > HTH
    >
    > --
    > 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, Jun 4, 2005
    #13
  14. On 4 Jun 2005 09:53:14 -0700, DKM wrote:

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

    --
    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, Jun 5, 2005
    #14
  15. DKM

    DKM Guest

    Andrew Thompson wrote:
    > On 4 Jun 2005 09:53:14 -0700, DKM wrote:
    >
    > > 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() )'.



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



    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, Jun 5, 2005
    #15
  16. DKM

    DKM Guest

    Roland wrote:
    > On 26-5-2005 16:01, DKM wrote:
    > >
    > > Andrew Thompson wrote:
    > >
    > >>On 26 May 2005 05:24:37 -0700, DKM wrote:
    > >>
    > >>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. ]

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

    >
    > <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/thread/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,
    >
    > Roland de Ruiter
    > ___ ___
    > /__/ w_/ /__/
    > / \ /_/ / \
    DKM, Jun 12, 2005
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. paolo marocco

    VM Browser Plug-In configuration

    paolo marocco, Oct 19, 2004, in forum: Java
    Replies:
    0
    Views:
    461
    paolo marocco
    Oct 19, 2004
  2. Bill Janssen

    Browser plug-in for Python?

    Bill Janssen, Jul 13, 2005, in forum: Python
    Replies:
    0
    Views:
    424
    Bill Janssen
    Jul 13, 2005
  3. =?ISO-8859-1?Q?Gregory_Pi=F1ero?=

    Web Browser Pygame Plug-in?

    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=, Jul 6, 2006, in forum: Python
    Replies:
    5
    Views:
    935
    Ravi Teja
    Jul 10, 2006
  4. Shane Hathaway

    Re: Web Browser Pygame Plug-in?

    Shane Hathaway, Jul 7, 2006, in forum: Python
    Replies:
    0
    Views:
    473
    Shane Hathaway
    Jul 7, 2006
  5. George Maney
    Replies:
    1
    Views:
    274
    Lucien
    Jan 22, 2004
Loading...

Share This Page