User 151fddb1df
27-05-2015 07:50:36
Hi,
I have an instance of marvinjs on a web page to sketch a molecule and I wanted to get an image of this molecule. So I tried the code below and it worked just fine.
var marvinSketcherInstance;
$(document).ready(function handleDocumentReady (e) {
// get the reference to the Marvin JS editor
MarvinJSUtil.getEditor("#sketch").then(function (sketcherInstance) {
marvinSketcherInstance = sketcherInstance;
initControl();
},function (error) {
alert("Cannot retrieve sketcher instance from iframe:"+error);
});
});
function initControl () {
// the export button
$("#btn-export").on("click", function (e) {
var settings = {
'width' : 150,
'height' : 150
};
marvinSketcherInstance.exportStructure("jpeg", settings).then(function(source) {
exportImage(source);
}, function(error) {
alert("Image export failed:"+error);
});
});
}
function exportImage(dataUrl) {
// set image source for the existing hidden image tag and display it.
$("#image").attr("src", dataUrl);
$("#imageContainer").css("display", "inline-block");
}
However, I want to dislay this image on another webpage so I tried to put the url in an variable but once on the other webpage it's gone (even if put in a session variable). I also tried with the function molToDataUrl but so far even if I'm able to have the url on the webpage diplaying the sketcher, I loose it as soon as I'm not on this page anymore.
Do you have any idea on how I should to display this image on a different web page than the one diplaying the sketcher please ? Maybe I'm missing a step here ?
Thanks for your help :)