The callback is used to terminate the javascript timeoutHandler that is used to initiate the download of the jnlp if no response locally. What happens then is while the local instance responds, a new download is initiated launching another session, thus you end up with another instance of IGV running. This used to work fine, but recently it does not with Firefox. Something has changed recently and I am not sure what. This was derived from example code
function timeoutHandler(locusStr) {
// created in PERL code above
var webstart_url = '/pwa/igv.php?locus=&sessionURL=${urlbase}/xtmp/${userRoot}/${OUT}';
// determine if webstart is available - code taken from sun site
var userAgent = navigator.userAgent.toLowerCase();
// user is running windows
if (userAgent.indexOf("msie") != -1 && userAgent.indexOf("win") != -1) {
document.write("<OBJECT " +
"codeBase=
http://java.sun.com/update/1.5.0/jinstall-1_5_0_05-windows-i586.cab " +
"classid=clsid:5852F5ED-8BF4-11D4-A245-0080C6F74284 height=0 width=0>");
document.write("<PARAM name=app VALUE=" + webstart_url + ">");
document.write("<PARAM NAME=back VALUE=true>");
// alternate html for browsers which cannot instantiate the object
document.write("<A href='
http://java.sun.com/j2se/1.5.0/download.html'>Download Java WebStart</A>");
document.write("</OBJECT>");
}
// user is not running windows
else if (webstartVersionCheck("1.6")) {
window.location = webstart_url;
}
// user does not have jre installed or lacks appropriate version - direct them to sun download site
else {
window.open("
http://jdl.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=java.com",
"needdownload");
}
function callBack() {
clearTimeout(timeoutVar);
}
function appRequest(locusString) {
// be good and remove the previous script element
// although, based on debugging, im not sure this really does anything
var oldScript = document.getElementById(SCRIPT_ELEMENT_ID);
if (oldScript) { oldScript.parentNode.removeChild(oldScript); }
// alert('Relocate to ' + locusString);
var localURLrelo = "
http://localhost:60151/goto?locus=" + locusString + "&callback=callBack();";
// create new script
var newScript = document.createElement("script");
newScript.id = SCRIPT_ELEMENT_ID;
newScript.setAttribute("type", "text/javascript");
newScript.setAttribute("src", localURLrelo);
// add new script to document (head section)
var head = document.getElementsByTagName("head")[0];
head.appendChild(newScript);
// disable link
// we do this because some browsers
// will not fetch data if the url has been fetched in the past
//disableLink("1");
// set timeout - handler for when IGV is not running
timeoutVar = setTimeout("timeoutHandler('" + locusString +"')", 3000);
}
Maybe there is a different mechanism for detecting a locally running copy that is more accurate? As it stands, every update to the local instance ends up initiating a jnlp download…the code is from a bit back.
edward