3 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
4 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
6 * This file is part of Jalview.
8 * Jalview is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 <head><title>Opening JalviewLite from Javascript</title>
22 <SCRIPT type="text/javascript">
24 // From http://snipplr.com/view.php?codeview&id=1272
25 //----------------------------------------
26 //Wrapper function for constructing a request object.
28 // reqType: The HTTP request type, such as GET or POST.
29 // url: The URL of the server program.
30 // asynch: Whether to send the request asynchronously or not.
31 //----------------------------------------
33 function httpRequest(reqType,url,asynch,respHandle) {
35 // Mozilla-based browsers
36 if (window.XMLHttpRequest) {
37 request = new XMLHttpRequest();
38 } else if (window.ActiveXObject) {
39 request = new ActiveXObject("Msxml2.XMLHTTP");
41 request = new ActiveXObject("Microsoft.XMLHTTP");
45 // Request could still be null if neither ActiveXObject
46 // initialization succeeded
48 // If the reqType param is POST, then the fifth arg is the POSTed data
49 if (reqType.toLowerCase() != "post") {
50 initReq(reqType, url, asynch, respHandle);
53 var args = arguments[5];
54 if (args != null && args.length > 0) {
55 initReq(reqType, url, asynch, respHandle, args);
59 alert("Your browser does not permit the use of all " +
60 "of this application's features!");
65 //----------------------------------------
66 //Initialize a request object that is already constructed
67 //----------------------------------------
69 function initReq(reqType, url, bool, respHandle) {
71 // Specify the function that will handle the HTTP response
72 request.onreadystatechange = respHandle;
73 request.open(reqType, url, bool);
74 // If the reqType param is POST, then the
75 // fifth argument to the function is the POSTed data
76 if (reqType.toLowerCase() == "post") {
77 // Set the Content-Type header for a POST request
78 request.setRequestHeader("Content-Type", "application/x-ww-form-urlencoded; charset=UTF-8");
79 request.send(arguments[4]);
84 alert("The application cannot contact the server at the moment. " +
85 "Please try again in a few seconds.\n" +
86 "Error detail: " + errv.message);
90 // jalview launching with fetched data
92 function startJalview(aligURL,title,alwvar) {
94 httpRequest("get",aligURL,true,function() {
95 if (request.readyState == 4) {
96 alignment = request.responseText;
97 eval("var "+alwvar+" = document.JalviewLite.loadAlignment(alignment,title)");
106 <applet name="JalviewLite" code="jalview.bin.JalviewLite"
107 archive="jalviewApplet.jar" width="0" height="0">
108 <param name="debug" value="true"/>
109 <param name="showbutton" value="false"/>
113 <input type="button" name="Button1" value="Start"
114 onClick="startJalview('plantfdx.fa','Button1.alignment','alwvar')"/>