2 <head><title>Opening JalviewLite from Javascript</title>
5 <SCRIPT type="text/javascript">
7 // From http://snipplr.com/view.php?codeview&id=1272
8 //----------------------------------------
9 //Wrapper function for constructing a request object.
11 // reqType: The HTTP request type, such as GET or POST.
12 // url: The URL of the server program.
13 // asynch: Whether to send the request asynchronously or not.
14 //----------------------------------------
16 function httpRequest(reqType,url,asynch,respHandle) {
18 // Mozilla-based browsers
19 if (window.XMLHttpRequest) {
20 request = new XMLHttpRequest();
21 } else if (window.ActiveXObject) {
22 request = new ActiveXObject("Msxml2.XMLHTTP");
24 request = new ActiveXObject("Microsoft.XMLHTTP");
28 // Request could still be null if neither ActiveXObject
29 // initialization succeeded
31 // If the reqType param is POST, then the fifth arg is the POSTed data
32 if (reqType.toLowerCase() != "post") {
33 initReq(reqType, url, asynch, respHandle);
36 var args = arguments[5];
37 if (args != null && args.length > 0) {
38 initReq(reqType, url, asynch, respHandle, args);
42 alert("Your browser does not permit the use of all " +
43 "of this application's features!");
48 //----------------------------------------
49 //Initialize a request object that is already constructed
50 //----------------------------------------
52 function initReq(reqType, url, bool, respHandle) {
54 // Specify the function that will handle the HTTP response
55 request.onreadystatechange = respHandle;
56 request.open(reqType, url, bool);
57 // If the reqType param is POST, then the
58 // fifth argument to the function is the POSTed data
59 if (reqType.toLowerCase() == "post") {
60 // Set the Content-Type header for a POST request
61 request.setRequestHeader("Content-Type", "application/x-ww-form-urlencoded; charset=UTF-8");
62 request.send(arguments[4]);
67 alert("The application cannot contact the server at the moment. " +
68 "Please try again in a few seconds.\n" +
69 "Error detail: " + errv.message);
73 // jalview launching with fetched data
75 function startJalview(aligURL,title,alwvar) {
77 httpRequest("get",aligURL,true,function() {
78 if (request.readyState == 4) {
79 alignment = request.responseText;
80 eval("var "+alwvar+" = document.JalviewLite.loadAlignment(alignment,title)");
89 <applet name="JalviewLite" code="jalview.bin.JalviewLite"
90 archive="jalviewApplet.jar" width="0" height="0">
91 <param name="debug" value="true"/>
92 <param name="showbutton" value="false"/>
96 <input type="button" name="Button1" value="Start"
97 onClick="startJalview('plantfdx.fa','Button1.alignment','alwvar')"/>