// use this file to control VTJ by doing these things to your html document: // 1. in your // 3. Now you can call: DisplayImage(newDocName); anywhere in your html document, or more important, you can call // parent.DisplayImage(newDocName); from a frame when your html document is a frameset // opener.DisplayImage(newDocName); from a window that you open from your html document // 'newDocName' is the URL to the image, relative to the "BufferVol" parameter of the applet // // The standard approach to using this function to display an image from a HTML link: // Link Text if any // // If you are opening viewer in a separate window and client computers may have pop-up blockers, a different approach will open directly from the link if a pop-up // blocker prevents opening a window from Javascript, construct a link to display an image as follows: // // Link Text if any // Tested on Windows for IE, Firefox, Netscape, Opera. // Tested on Mac for IE, Firefox, Netscape, Opera, Camino if ((typeof vtj) == "undefined") var vtj = null; if (((typeof documentName)== "undefined") || documentName== null) var documentName = ""; if (((typeof imagingURL) == "undefined") || imagingURL == null) var imagingURL = "viewimage.html"; // IE uses different screen positioning (see below) var isIE = (navigator.userAgent.indexOf("MSIE") >= 0); var isOpera = (navigator.userAgent.indexOf("Opera") >= 0); // used to detect a pop-up blocker that stops the Javascript var popupBlocked = false; // This function will return false if the window cannot be opened (pop-up blocker), this allows an HTML link to directly // open the window if DisplayImage() called from 'onClick' function of the link and fails function DisplayImage(newDocName) { // this variable is picked up by 'viewimage.html' and used to display the image: documentName=newDocName; if (isOpera) CheckClosed(); // workaround for opera bug that does not detect window closed if (vtj == null || vtj.closed) { // if viewing in separate window, and window not opened yet or was closed... // some pop-up blockers will kill the javascript right at window.open, so we set a flag here so at least // on the next click we won't try and window will be opened directly from the link if (popupBlocked) return(false); popupBlocked = true; // These sizes (650 by 860) show an 8 by 11 page at full size bestWidth = 650; bestHeight = 860; winHeight = screen.availHeight - 50; // leave room for windows start menu bar, and status line winWidth = screen.availWidth - 10; xpos = 0; ypos = 0; if (winWidth > bestWidth) { xpos = (winWidth - bestWidth) - 10; // place window on right side winWidth = bestWidth; } if (winHeight > bestHeight) { ypos = (winHeight - bestHeight) / 2; // center window vertically winHeight = bestHeight; } if (isIE) screenPosOption = "left="+xpos+",top="+ypos; else screenPosOption = "screenX="+xpos+",screenY="+ypos; // if 'viewimage.html' comes from same server as this javascript, you may eliminate ' + "?" + escape(documentName) ' from below to remove // image name from URL. unescape converts special characters to %NN notation vtj = window.open(imagingURL + "#" + documentName, "ImageViewer", "width="+winWidth+",height="+winHeight+"," + screenPosOption + ",status=yes,resizable=yes,address=yes"); popupBlocked = false; if (vtj == null || vtj.closed) // pop-up blocker detected return false; // return false, we failed to display the image, the link will bring up image manually vtj.focus(); // seems redundant but some system do not open the window in front } else { // window is open, just tell applet new document name fetchImage(newDocName); } return true; } // Certain browsers (e.g. IE on Macintosh) do not support calls from Javascript to Java, so we must reload the applet // Some browsers cannot handle onerror either, so we have to detect whether the JavaScript to Java fails. var saveOnError = window.onerror; var errorOccured; var noJS2J = false; function reloadVTJ(msg, url, line) { noJS2J = true; errorOccured = true; window.onerror = saveOnError; // if 'viewimage.html' comes from same server as this javascript, you may use the line below instead to remove image // name from URL vtj.location = vtj.location.href; // vtj.location.replace(imagingURL + "#" + documentName); return true; } function fetchImage(newDocName) { window.onerror = reloadVTJ; vtj.focus(); if (noJS2J) { reloadVTJ("No JavaScript to Java", "self", "0"); } else { errorOccured = false; noJS2J = true; if ((typeof vtj.document.viewer) == "undefined") { reloadVTJ("No JavaScript to Java", "self", "0"); noJS2J = false; // this is probably a user double-click, so don't give up on JS2J return; } vtj.document.viewer.setDocName(newDocName); noJS2J = errorOccured; window.onerror = saveOnError; } } // Work around for opera bug which does not set 'window.closed' variable when a browser window closes. So // we must test if window was opened by attempting to focus window function CheckClosed() { if (vtj != null && !vtj.closed) { // if we belive window is open try { vtj.focus(); // this fails if window is really closed } catch (err) { vtj = null; } } }