Prevent Marvin applet from taking focus

User e9b312fb05

15-05-2008 14:07:25

Hi all,





I have a frameset of two frames (left/right). A form goes to the left frame and I can set the focus to any form field as expected using onLoad="document.form.field.focus()". Some seconds later the Marvin applet is loaded into the right frame and takes the focus away from the form field.





How can I prevent this?








Paul

ChemAxon 7c2d26e5cf

15-05-2008 14:31:16

Marvin applets automatically grap the focus by startup.


To avoid it, pass the focus after the applet started.


Marvin applets supports event handling. It means you can define Javascript methods for the applet that is invoked when the state of the applet is changed.


The molLoaderFinishedEvent applet parameter is useful to invoke a JavaScript method when the molecule loaded into the applet. I recommend to call your code (to pass focus) by this event.


Alternative solution can be the listenpropertychange applet parameter that helps to catch all property change events that is dropped by the applet.


Please take a look at to this example. It demonstrates how to use listenpropertychange parameter: http://www.chemaxon.com/test/example-propertychange.html

User e9b312fb05

15-05-2008 15:15:06

Thanks for your fast response. I tried the 'alert' example and it works fine. But I cannot set the focus to a specified form field. The form is called 'molform' and there is a text field called 'cas':








script type="text/javascript">


msketch_name = "MSketch";


msketch_mayscript=true;


msketch_begin("https://pwe.no-ip.org/chemicals/marvin","600","385");


msketch_param("importConv","-H,-a");


msketch_param("implicitH","hetero");


msketch_param("bondDraggedAlong","false");


msketch_param("verticalbar","true");


msketch_param("menubar","false");


msketch_param("reactionSupport","false");


msketch_param("3dviewerEnabled","false");


msketch_param("background", "#ffffff");


msketch_param("molbg", "#ffffff");


msketch_param("mol","../../chemicals/mol/108-86-1.mol");


msketch_param("molLoaderFinishedEvent","js:document.molform.cas.focus()");


msketch_end();


var isJs2Java = isLiveConnect();


setPath("../..");


function submitMethod() {


document.molform.molecule.value = getResult();


document.molform.submit();


}


function getMol(format) {


if((document.MSketch != null) && isJs2Java) {


var s = document.MSketch.getMol(format);


s = unix2local(s);


document.molform.molecule.value = s;


document.molform.submit();


window.close();


} else if(!isJs2Java) {


setMethod("MSketch.getMol","java.lang.String");


addMethodParam(format);


setPostJsMethod("parent.submitMethod()");


runMethod();


} else {


alert("Cannot import molecule:\n" +


"no JavaScript to Java communication in your browser.\n");


}


}


</script>








Any idea what can be wrong?

ChemAxon 7c2d26e5cf

17-05-2008 09:05:51

I have simplified your example and it works for me. ("isJs2Java" condition does not need because all modern browser can handle Java - JavaScript communication.)


After loading the applet, the cursor is flashing in the text field.


Please see the attached example.