My experience is the "appendChild" is overkill for what you generally need.
Just make sure you have

jmolSetDocument(0)

and then the "applet" you get from

var x = jmolApplet(.....)

can be inserted into any div. HOWEVER, as I recall there are problems with
some browsers not being able to communicate properly with applets created
after the page is loaded. I could be wrong about that, but I think Opera is
the offender.

Here's a snippet from
http://www.stolaf.edu/people/hansonr/sudoku/sudoku3d.js that loads an applet
into a div after page load for
http://www.stolaf.edu/people/hansonr/sudoku/to show a 3D version of
the logical pathways of a Sudoku puzzle.

function createAppletInline(smodel,script){
        if(isjmolinitialized && !isjmolreset && !isliveconnecterror){
                isliveconnecterror=1
                document.getElementById("jmolApplet0").script(script)
                isliveconnecterror=0 //won't get here if we have a LiveConnect 
error (Opera)
                return
        }
        if(!isjmolinitialized)jmolInitialize(".")
        isjmolinitialized=1
        isjmolreset=0
        jmolSetDocument(0)
        var s=jmolApplet(450,"set perspectivedepth OFF;"+script,"0")
        s=addParam(s,"loadInline",smodel.replace(/\n/g,"|"))
        s=addParam(s,"messageCallback","clickModel")
        document.getElementById("apphere").innerHTML=s

}

were the addParam function inserts a parameter code into the HTML before it
is sent out. I'm pretty sure Opera doesn't allow this.

function addParam(sappcode,sname,svalue){
        return sappcode.replace(/\<param/,"<param name=\""+sname+"\"
value=\""+svalue+"\" />\n<param")
}



Make sure you use () after any function call in JavaScript.


addParam

is the function contents -- as a string, as above

addParam()

executes the function.





On 8/27/08, Jeff Hansen <[EMAIL PROTECTED]> wrote:
>
> Believe me I've been doing plenty of that, but I also have been finding
> trial and error to be very instructive too.  I did take a look at your
> divs.js file.  I don't yet understand all of it.  I tried your divFind and
> divWrite functions and I'm pretty sure I'm understanding what they do.
>  Unfortunately the divWrite doesn't do what I want.  I want to put a Jmol
> applet into the div and this function appears to only write text into a div.
>  I tried divWrite(jmolID, newJmol) and divWrite(jmolID, eval(newJmol) where
> jmolID is a variable that holds the div's id and newJmol is a Jmol applet
> object.  Unfortunately both off these do the same thing which is to write
> the function used to create the Jmol applet object into the into the div as
> text.
> I've also tried the following code:
>
> document.getElementById(jmolID).appendChild(newJmol);
>
> which produces the following error message in FireBug:
>  uncaught exception: Node cannot be inserted at the specified point in the
> hierarchy (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)
>
>
> document.getElementById(jmolID).update(newJmol);
>
> gives the error:  document.getElementById(jmolID).update is not a function
>
>
> I've tried several variations.  I got it to work once using:
> newDiv.update(jmolApplet(400, eval(_jmolApplet.loadString))); where newDiv
> was a reference to a div element, but this only worked in Safari and not
> Firefox.
>
> Unfortunately, everywhere I've read about adding something to a div element
> the something being added is text.  I can't find anywhere that gives an
> example off adding some other kind of object.
>
> Perhaps I should give it up.  I thought it would be possible to create a
> Jmol applet object and add it to the web page.  Then I would be able to
> include methods in the Jmol applet object constructor to change jmol
> parameters and such.  Obviously there are other ways to do that, but this
> just seems an attractive way to me for some reason.
>
>
> ***********************************************
> Jeff Hansen
> Department of Chemistry and Biochemistry
> DePauw University
> 602 S. College Ave.
> Greencastle, IN 46135
> [EMAIL PROTECTED]
> ***********************************************
>
>
> On Aug 27, 2008, at 2:14 PM, Robert Hanson wrote:
>
> >> I'm working towards my own at this point and I'm afraid looking at yours
> will just prevent my learning how to do it myself.
>
> Shame! NEVER say that! The way to learn this is by adapting anything you
> can find. That's the great thing about JavaScript. Learn how these code
> fragments work by testing it in your own application. You will learn lots.
>
> Bob
>
> --
> Robert M. Hanson
> Professor of Chemistry
> St. Olaf College
> Northfield, MN
> http://www.stolaf.edu/people/hansonr
>
>
> If nature does not answer first what we want,
> it is better to take what answer we get.
>
> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
>  -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
>
> http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
> Jmol-users mailing list
> Jmol-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Jmol-users mailing list
> Jmol-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>


-- 
Robert M. Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to