pass javascript alert by java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsn
    New Member
    • Sep 2007
    • 237

    pass javascript alert by java

    hello everyone.
    i am working on a program which access a website and reads the source code of the website. this part is doing well, but the issue which i am facing is that there is a page which in javascript it use the alert function so a normal user just presses the ok button.
    how can i make java press the ok button so it could passes the alert of javascript

    kind regards
    hsn
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Not possible. Java can read that site's content but cannot modify it (remotely). The code modifications would have to happen on the site's server.

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      Just analyze what the javascript is doing (which URL-parameters it is setting or which parameters of the form it is changing) and then send a request with these changed parameters.

      You have to analyze that manually. No computer can analyze if a javascript function ever stops and returns a value or not. (see Alan M. Turing halting problem, theorhetical computation science). And which value it delivers.

      You can only reprogram (simulate) a browser (like firefox, IE) and then let that javascript function run inside and if you are lucky it stops and you get the resulting parameter which you can then send.

      I heard that JDK1.6 can run javascript inside... Maybe you can try this and then you let it run in a thread, so if you don't get a result from your javascript function after some time, you just kill the thread and print out an error....
      I googled and found following:

      Code:
      import org.apache.bsf.BSFManager;
      final BSFManager manager = new BSFManager();
      manager.eval(    "javascript", "(java)", 1, 1,     "var f = function (what) { return 'hello, ' + what; }; f('Javascript);");

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by chaarmann
        I heard that JDK1.6 can run javascript inside... Maybe you can try this and then you let it run in a thread, so if you don't get a result from your javascript function after some time, you just kill the thread and print out an error....
        I googled and found following:

        Code:
        import org.apache.bsf.BSFManager;
        final BSFManager manager = new BSFManager();
        manager.eval(    "javascript", "(java)", 1, 1,     "var f = function (what) { return 'hello, ' + what; }; f('Javascript);");
        No need for the Apache stuff; Java has its own little framework for scripting. Have
        a look at the Scripting article in the Howtos section.

        kind regards,

        Jos

        Comment

        • hsn
          New Member
          • Sep 2007
          • 237

          #5
          Originally posted by JosAH
          No need for the Apache stuff; Java has its own little framework for scripting. Have
          a look at the Scripting article in the Howtos section.

          kind regards,

          Jos
          hello Jos, thanks for the article you linked me to it was great.
          i am now searching about it online studying it, hoping that it will help with my problem.
          i was hoping you would be able to help me with it too.
          when the website, which my program is connected to by URLConnection, runs the alert function of javascript, how can i make the ScriptEngineMan ager passes through that alert? i know i should return true so javascript passes me through. but, how could i make the ScriptEngineMan ager return that value to website and to javascript ???

          thanks a lot Jos

          kind regards
          hsn

          Comment

          Working...