User cbb759276f
11-02-2016 17:53:11
Hi,
I'm not sure if this is a MarvinJS question or a JChem Web Services question...
With our current implementation of the MarvinSketch Java applet, we can import any MRV file which shares the same webserver as MarvinSketch.
For example, if MarvinSketch is hosted on http://server/marvin/marvin.html, and we upload example.MRV to the same folder, by simply typing in example.MRV into MarvinSketch IMPORT box, it will import the MRV file from the server directly.
Based around on this code:
<input TYPE=BUTTON VALUE="Import" onClick="importMol(null)">
</form>
[...]
function importMol(opts) {
if(document.MSketch != null) {
var s = document.MolForm1.MolTxt.value;
document.MSketch.setMol(s,opts);
document.MolForm1.MolTxt.value="";
} else {
alert("Cannot import molecule:\n"+
"no JavaScript to Java communication in your browser.\n");
}
}
Can you do likewise with MarvinJS?
ChemAxon 7c2d26e5cf
15-02-2016 10:59:19
Please, see the following example. It demonstrates how to set a structure to the Marvin JS editor.
https://marvinjs-demo.chemaxon.com/latest/examples/example-setmol.html
In the above example, the molecule source is inline the HTML code. To load the source from an external file, you have to modify the code a bit.
So, you need an AJAX request to retrieve the content of the desired file. After that, you can call the imporStructure function of the Marvin JS editor to load the structure into the editor.
function importMol(format) {
var url = document.MolForm1.MolTxt.value;
$.ajax(url).done(function(source) {
marvinSketcherInstance.importStructure(format, source).catch(function(error) {
alert("Cannot import structure.");
}
}).fail(function(error) {
alert("Cannot load "+url);
});
}
The above example uses JQuery library to create an AJAX request. Of course you can use any other JavaScript library to create an AJAX request.
User 47ec854e59
15-02-2016 12:30:01
It worked.Thanks a lot Tamas.