Maximization of Marvin Applets in Perecentages

User 4616a6b00d

10-01-2014 05:47:26

Hi,


 


Here is the below code : 


msketch_name="MSketch";


msketch_begin("../marvin/",600,400);


msketch_param("mol",mrvData);


msketch_end();




Is there any way to specify the height and width attribute in percentages?


 



ChemAxon 2c555f5717

10-01-2014 09:28:25

Hi!


   Unfortunately applet (or object/embed) tag is not like the standard HTML tags. It needs a predefined size that it can forward to the Java applet. However you can use a JavaScript to precalculate the available space and forward it to the applet. Like this:


<script type="text/javascript" src="./marvin/marvin.js"></script>
<script type="text/javascript">

var viewportwidth;
var viewportheight;

// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

msketch_begin("./marvin",0.9*viewportwidth,0.7*viewportheight);
msketch_param("mol", "C1cCcCc1");
msketch_end();
</script>

(The viewport calculation script comes from this site.)


   You can also connect to the resize event of the window, but you have to reload the page to make the changes in applet visible.


Regards:
Balázs