views:

38

answers:

1

Hi all:

Basically I want my Java Applet to simulate an url has been clicked, once a certain event listener has been executed.

Say, before I have a link in html:

<a href='destinationpage.php?pid=1001' target='rightFrame' />

I'd like to keep the same link to php intact, and when Applet actually invoke the click simulation method, the "target" attribute can also be used to control the behavior.

Similar SO thread found at here, but it doesn't have an answer.

I have little experience in this area, but I am okay with Java programming so long as someone can give me the suggestion of where to get started with.

Many thanks in advance.

Edit:

Okay, tried to get JSObject from the netscape.javascript package to work, added plugin.jar into CLASSPATH, unfortunately I finally got an ExceptionInInitializerError, so this approach failed, unless I can know how to debug in such a mess...

+1  A: 

You could call the url directly in the applet but if you want to reference the link in the page something like the following should work. I have not tested this though.

getAppletContext().showDocument(new URL("javascript:function() {
  document.getElementById('mylink').click();
}"));
}
HeathLilley
@HeathLilley: unfortunately I don't this this would work with my Firefox 3.0.15...
Michael Mao
@HeathLilley: Actually I know how to mimic a simple plain POST method in Java/Applet, but the "target" attribute is the messy part in this case.
Michael Mao
getAppletContext().showDocument(new URL("http://www.google.com"), "_blank");
HeathLilley
Keep hitting the enter button. There is a version of the showDocument method that takes a target argument as a string so if you can get a reference to the link in a javascript method you should be able to get the target value.
HeathLilley
@HeathLilley : Thanks for the tip and I will try it later :)
Michael Mao