MarvinSketch Example 3.3

Press the Load button to load "caffeine.mol" into the sketcher.

<form onSubmit="return false">
<input TYPE=BUTTON VALUE="Load" onClick="loadMol()">
</form>

<script LANGUAGE="JavaScript1.1" SRC="../../marvin.js"></script>
<script LANGUAGE="JavaScript1.1">
<!--
function loadMol() {
	if(document.MSketch != null) {
		document.MSketch.setMol("../../mols-2d/caffeine.mol");
	} else {
		alert("Cannot load molecule:\n"+
		      "no JavaScript to Java communication in your browser.\n");
	}
}
msketch_name = "MSketch";
msketch_begin("../..", 460, 380);
msketch_param("scale", "60");
msketch_param("viewonly", "true");
msketch_end();
//-->
</script>

Note that the function that loads the molecule must not be named load(), because this name conflicts with a built-in JavaScript function in Netscape 6 (and later versions). That is why we named it loadMol() here.


In some cases you don't have the molfile in an URL, and it would be easier to pack it into the HTML as in the previous example. You can also do that in JavaScript.