I am trying to access a variable value in a script in my HTML file from a external javascript function....Something looking like this:
In my HTML page I have this:
<div id="jsmolwindow" style="display:none;">
<script language="javascript" type="text/javascript">
var scrt_var = "bucky.mol";
openPage = function() {
location.href = "javascript:Jmol.script(jmolApplet0,'load "+scrt_var+"')";
}
</script>
<a href ="javascript:openPage()"><FONT COLOR="BLACK">View 3D Molecule</FONT></a>
<script type="text/javascript">
jmolApplet0 = Jmol.getApplet("jmolApplet0", Info);
</script>
</div>
That is displaying the image in scrt_var here bucky.mol.
Now I would want scrt_var to be "read" from a value defined in a external js file looking like that:
ui.onClick_exec_optimizer=function()
{
ui.showDialog('CARunning');
function GetAdress(){
return "bucky.mol";}
How can I link GetAdress and scrt_var ?
Thanks!
Write the HTML script also in separate .js file. and in your HTML <head>
do like this
<script type="text/javascript" src="first.js"></script>
<script type="text/javascript" src="second.js"></script>
now you can read any variable across any file. simple
Here the solution:
In html:
<div id="jsmolwindow" style="display:none;">
<a href="#" id="mylink"><FONT COLOR="BLACK">View 3D Molecule</FONT></a>
<script type="text/javascript">
jmolApplet0 = Jmol.getApplet("jmolApplet0", Info);
</script>
</div>
In js file:
ui.onClick_exec_optimizer=function()
{
var scrt_var = "bucky.mol";
document.getElementById("mylink").href = "javascript:Jmol.script(jmolApplet0,'load "+scrt_var+"')";
}
That works fine.
Thanks for your help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.