I tried to write a code that prevents 2 creeps (harvester) from going to the same destination and binds them to that destination until its full.
on line 55 I get an error which is understandable
55: creep.memory.targetID = targets[checkTarget].id;
for a reason that I am not seeing targets[checkTarget] is null
Can anyone tell me what i am doing wrong?
var roleHarvester = {
/** #param {Creep} creep **/
run: function(creep) {
if (!creep.memory.targetID) creep.memory.targetID = "not given";
console.log(creep.memory.targetID);
if (creep.carry.energy < creep.carryCapacity) {
var nearestSource = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE);
if (creep.harvest(nearestSource) == ERR_NOT_IN_RANGE) {
creep.moveTo(nearestSource, {
visualizePathStyle: {
stroke: '#ffaa00'
}
});
}
} else {
if (creep.memory.targetID != "not given") {
console.log("should not be not given");
if (Game.getObjectById(creep.memory.targetID).hits == Game.getObjectById(creep.memory.targetID).hitsMax) {
creep.memory.targetID = "not given";
var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_SPAWN ||
structure.structureType == STRUCTURE_EXTENSION ||
structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity;
}
});
} else {
if (creep.transfer(Game.getObjectById(creep.memory.targetID), RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(Game.getObjectById(creep.memory.targetID), {
visualizePathStyle: {
stroke: '#ffffff'
}
});
}
}
} else {
var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_SPAWN ||
structure.structureType == STRUCTURE_EXTENSION ||
structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity;
}
});
console.log(targets);
for (var checkTarget in targets) {
console.log(checkTarget);
console.log(targets[checkTarget]);
for (var name in Game.creeps) {
if (targets[checkTarget] = Game.getObjectById(Game.creeps[name].memory.targetID)) {
var fail = true;
break;
}
var fail = false;
}
if (fail == true) continue;
console.log(Game.getObjectById(targets[checkTarget]));
creep.memory.targetID = targets[checkTarget].id;
break;
}
}
}
}
};
module.exports = roleHarvester;
Something wrong in the following if condition:
for(var name in Game.creeps) {
if(targets[checkTarget] = Game.getObjectById(Game.creeps[name].memory.targetID)){
Probably you mean == ?
Related
I've a following function as:
public function rawFlexClickDataGridItem(datagridId:String, colIndex:String, itemText:String):String
{
var child:Object = appTreeParser.getElement(datagridId);
if(child == null)
{
return ErrorMessages.getError(ErrorMessages.ERROR_ELEMENT_NOT_FOUND, [datagridId]);
}
// Assumes the DataGrid has only one ListBaseContentHolder
var dgContentList:Object = Tools.getChildrenOfTypeFromContainer(child,
ReferenceData.LISTBASECONTENTHOLDER_DESCRIPTION)[0];
for each (var array:Array in dgContentList.listItems)
{
var item:Object = array[int(colIndex)];
if(item.hasOwnProperty("numChildren"))
{
for(var i:int = 0;i < item.numChildren;i++)
{
if((item.getChildAt(i).hasOwnProperty("text") && (item.getChildAt(i).text == itemText)) ||
(item.getChildAt(i).hasOwnProperty("label") && (item.getChildAt(i).label == itemText)))
{
return String(item.getChildAt(i).dispatchEvent(new MouseEvent(MouseEvent.CLICK)));
}
}
}
if((item.hasOwnProperty("text") && (item.text == itemText)) ||
(item.hasOwnProperty("label") && (item.label == itemText)))
{
return String(item.getChildAt(i).dispatchEvent(new MouseEvent(MouseEvent.CLICK)));
}
}
return ErrorMessages.getError(ErrorMessages.ERROR_TEXT_NOT_FOUND, [itemText,colIndex]);
}
}
}
when I'm calling it from the javascript with providing (dataGrid,1,yellow) as arguments, I'm getting error #1069
My datGrid is as below:
Similar to my question last week here.
Again, I need to return the value green if it's true and red if it's false. The logic is right, it's just the styling that won't work, but I'm not sure why?
JS
var getAcrobatInfo = function () {
var noPDF = 'No PDF viewer installed';
var getBrowserName = function () {
return this.name = this.name || function () {
var userAgent = navigator ? navigator.userAgent.toLowerCase() : "other";
if (userAgent.indexOf("chrome") > -1) {
return "chrome";
} else if (userAgent.indexOf("safari") > -1) {
return "safari";
} else if (userAgent.indexOf("msie") > -1 || navigator.appVersion.indexOf('Trident/') > 0) {
return "ie";
} else if (userAgent.indexOf("firefox") > -1) {
return "firefox";
} else {
//return "ie";
return userAgent;
}
}();
};
var getActiveXObject = function (name) {
try {
return new ActiveXObject(name);
} catch (e) { }
};
var getNavigatorPlugin = function (name) {
for (key in navigator.plugins) {
var plugin = navigator.plugins[key];
if (plugin.name == name) return plugin;
}
};
var getPDFPlugin = function () {
return this.plugin = this.plugin || function () {
if (getBrowserName() == 'ie') {
return getActiveXObject('AcroPDF.PDF') || getActiveXObject('PDF.PdfCtrl');
} else {
return getNavigatorPlugin('Adobe Acrobat') || getNavigatorPlugin('Chrome PDF Viewer') || getNavigatorPlugin('WebKit built-in PDF');
}
}();
};
var isAcrobatInstalled = function () {
return !!getPDFPlugin();
};
var getAcrobatVersion = function () {
try {
var plugin = getPDFPlugin();
if (getBrowserName() == 'ie') {
var versions = plugin.GetVersions().split(',');
var latest = versions[0].split('=');
return parseFloat(latest[1]);
}
if (plugin.version) return parseInt(plugin.version);
return plugin.name
} catch (e) {
return noPDF;
}
}
return {Acrobat: isAcrobatInstalled()};
};
var info = getAcrobatInfo();
var pdf = document.getElementById('acrobat');
if (info.Acrobat) {
pdf.classList.add('green');
pdf.innerHTML = 'True';
}
else {
pdf.classList.add('red');
pdf.innerHTML = 'False';
}
}
HTML
<tr>
<td>PDF Viewer Enabled:</td>
<td id="acrobat"></td>
</tr>
CSS
#pdf.green {
color: #33CC33;
font-weight: bold;
}
#pdf.red {
color: #FF0000;
font-weight: bold;
}
I have JavaScript code which displays a multi coffee value.
If I am trying to display a single value coffee, its not going inside the else if.
I modified existing code but getting an undefined error.
Can you tell me how to fix it?
var multCoffees = false;
var singleCoffee = false;
if (Coffees.length > 1) {
multCoffees = true;
}
if (Coffees.length > 1) {
singleCoffee = true;
}
if (apptTimeCell) {
apptTimeHTML = MyDay.dish(allData, multCoffees, singleCoffee);
apptTimeCell.innerHTML = apptTimeHTML;
} else {
apptTimeCell = Util.cep("span", {
className: "appt-time"
});
patientRowTD.insertBefore(apptTimeCell, patCell);
}
dish: function (allData, multCoffees, singleCoffee) {
if (multCoffees) {
var htmlArr = [];
htmlArr.push(allData.APPT_TIME_DISPLAY, "<br/><span class='sub-detail'>", allData.MNEMONIC, "</span>");
console.log("multiCoffee" + allData.PROVIDER_MNEMONIC);
return htmlArr.join("");
} else if (singleCoffee) {
console.log("inside if" + allData.PROVIDER_MNEMONIC);
var htmlArr = [];
htmlArr.push(allData.APPT_TIME_DISPLAY, "<br/><span class='sub-detail'>", allData.PROVIDER_MNEMONIC, "</span>");
console.log("singleCoffee" + allData.PROVIDER_MNEMONIC);
return htmlArr.join("");
} else {
return allData.APPT_TIME_DISPLAY;
}
},
Working code:
var multCoffees = false;
if (Coffees.length > 1) {
multCoffees = true;
}
if (apptTimeCell) {
apptTimeHTML = MyDay.dish(allData, multCoffees);
apptTimeCell.innerHTML = apptTimeHTML;
} else {
apptTimeCell = Util.cep("span", {
className: "appt-time"
});
patientRowTD.insertBefore(apptTimeCell, patCell);
}
dish: function (allData, multCoffees) {
if (multCoffees) {
var htmlArr = [];
htmlArr.push(allData.APPT_TIME_DISPLAY, "<br/><span class='sub-detail'>", allData.MNEMONIC, "</span>");
console.log("multiCoffee" + allData.PROVIDER_MNEMONIC);
return htmlArr.join("");
} else {
return allData.APPT_TIME_DISPLAY;
}
},
Suppose Coffees.length is 2. You do this...
if (Coffees.length > 1) {
multCoffees = true;
}
...and 2 > 1, so now multCoffees is true, but then you do this, which checks the same thing...
if (Coffees.length > 1) {
singleCoffee = true;
}
and, since 2 > 1 still, now BOTH multCoffees AND singleCoffee are true. So when you try to do
if (multCoffees) {
...
} else if (singleCoffee) {
...
}
the first if branch is true, so it is executed, and the else branch is thus ignored (despite also being true). You probably meant to instead start with
if (Coffees.length == 1) {
singleCoffee = true;
} else if (Coffees.length > 1) {
multCoffees = true;
}
replace your first two ifs with this block:
if (Coffees.length == 1) {
singleCoffee = true;
}
else if(Coffees.length > 1){
multCoffees = true;
}
and then try it again!
I am having two pages. The next button in first pages brings the second page. The focus in second page is always moving down. So I need to use scroll bar to bring the bring the cursor top. I want to bring the focus to the top. my focus-handler.js is as follows:
var lastFocusedControlId = "";
function focusHandler(e) {
document.activeElement = e.originalTarget;
}
function appInit() {
if (typeof (window.addEventListener) !== "undefined") {
window.addEventListener("focus", focusHandler, true);
}
setFirstControl()
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
}
function pageLoadingHandler(sender, args) {
lastFocusedControlId = typeof (document.activeElement) === "undefined"
? "" : document.activeElement.id;
}
function focusControl(targetControl) {
if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
var focusTarget = targetControl;
if (focusTarget && (typeof (focusTarget.contentEditable) !== "undefined")) {
oldContentEditableSetting = focusTarget.contentEditable;
focusTarget.contentEditable = false;
}
else {
focusTarget = null;
}
try {
targetControl.focus();
if (focusTarget) {
focusTarget.contentEditable = oldContentEditableSetting;
}
}
catch (err) { }
}
else {
targetControl.focus();
}
}
function pageLoadedHandler(sender, args) {
if (typeof (lastFocusedControlId) !== "undefined" && lastFocusedControlId != "") {
var newFocused = $get(lastFocusedControlId);
if (newFocused) {
focusControl(newFocused);
}
}
}
function setFirstControl() {
var bFound = false;
// for each form
for (f = 0; f < document.forms.length; f++) {
// for each element in each form
for (i = 0; i < document.forms[f].length; i++) {
// if it's not a hidden element
if (document.forms[f][i].type != "hidden") {
// and it's not disabled
if (document.forms[f][i].disabled != true) {
try {
// set the focus to it
document.forms[f][i].focus();
var bFound = true;
}
catch (er) {
}
}
}
// if found in this element, stop looking
if (bFound == true)
break;
}
// if found in this form, stop looking
if (bFound == true)
break;
}
}
Sys.Application.add_init(appInit);
I was checking this code provided by Sun that can retrieve a list of the Java Runtime Environments installed on the machine. Here's the code formatted and with some functions removed so it's easier to read:
var deployJava = {
debug: null,
firefoxJavaVersion: null,
returnPage: null,
locale: null,
oldMimeType: 'application/npruntime-scriptable-plugin;DeploymentToolkit',
mimeType: 'application/java-deployment-toolkit',
browserName: null,
browserName2: null,
getJREs: function () {
var list = new Array();
if (deployJava.isPluginInstalled()) {
var plugin = deployJava.getPlugin();
var VMs = plugin.jvms;
for (var i = 0; i < VMs.getLength(); i++) {
list[i] = VMs.get(i).version;
}
} else {
var browser = deployJava.getBrowser();
if (browser == 'MSIE') {
if (deployJava.testUsingActiveX('1.7.0')) {
list[0] = '1.7.0';
} else if (deployJava.testUsingActiveX('1.6.0')) {
list[0] = '1.6.0';
} else if (deployJava.testUsingActiveX('1.5.0')) {
list[0] = '1.5.0';
} else if (deployJava.testUsingActiveX('1.4.2')) {
list[0] = '1.4.2';
} else if (deployJava.testForMSVM()) {
list[0] = '1.1';
}
} else if (browser == 'Netscape Family') {
deployJava.getJPIVersionUsingMimeType();
if (deployJava.firefoxJavaVersion != null) {
list[0] = deployJava.firefoxJavaVersion;
} else if (deployJava.testUsingMimeTypes('1.7')) {
list[0] = '1.7.0';
} else if (deployJava.testUsingMimeTypes('1.6')) {
list[0] = '1.6.0';
} else if (deployJava.testUsingMimeTypes('1.5')) {
list[0] = '1.5.0';
} else if (deployJava.testUsingMimeTypes('1.4.2')) {
list[0] = '1.4.2';
} else if (deployJava.browserName2 == 'Safari') {
if (deployJava.testUsingPluginsArray('1.7.0')) {
list[0] = '1.7.0';
} else if (deployJava.testUsingPluginsArray('1.6')) {
list[0] = '1.6.0';
} else if (deployJava.testUsingPluginsArray('1.5')) {
list[0] = '1.5.0';
} else if (deployJava.testUsingPluginsArray('1.4.2')) {
list[0] = '1.4.2';
}
}
}
}
if (deployJava.debug) {
for (var i = 0; i < list.length; ++i) {
alert('We claim to have detected Java SE ' + list[i]);
}
}
return list;
},
runApplet: function (attributes, parameters, minimumVersion) {
if (minimumVersion == 'undefined' || minimumVersion == null) {
minimumVersion = '1.1';
}
var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?$";
var matchData = minimumVersion.match(regex);
if (deployJava.returnPage == null) {
deployJava.returnPage = document.location;
}
if (matchData != null) {
var browser = deployJava.getBrowser();
if ((browser != '?') && ('Safari' != deployJava.browserName2)) {
if (deployJava.versionCheck(minimumVersion + '+')) {
deployJava.writeAppletTag(attributes, parameters);
}
} else {
deployJava.writeAppletTag(attributes, parameters);
}
} else {
if (deployJava.debug) {
alert('Invalid minimumVersion argument to runApplet():' + minimumVersion);
}
}
},
writeAppletTag: function (attributes, parameters) {
var startApplet = '<' + 'applet ';
var params = '';
var endApplet = '<' + '/' + 'applet' + '>';
var addCodeAttribute = true;
for (var attribute in attributes) {
startApplet += (' ' + attribute + '="' + attributes[attribute] + '"');
if (attribute == 'code' || attribute == 'java_code') {
addCodeAttribute = false;
}
}
if (parameters != 'undefined' && parameters != null) {
var codebaseParam = false;
for (var parameter in parameters) {
if (parameter == 'codebase_lookup') {
codebaseParam = true;
}
if (parameter == 'object' || parameter == 'java_object') {
addCodeAttribute = false;
}
params += '<param name="' + parameter + '" value="' + parameters[parameter] + '"/>';
}
if (!codebaseParam) {
params += '<param name="codebase_lookup" value="false"/>';
}
}
if (addCodeAttribute) {
startApplet += (' code="dummy"');
}
startApplet += '>';
document.write(startApplet + '\n' + params + '\n' + endApplet);
},
versionCheck: function (versionPattern) {
var index = 0;
var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?(\\*|\\+)?$";
var matchData = versionPattern.match(regex);
if (matchData != null) {
var familyMatch = true;
var patternArray = new Array();
for (var i = 1; i < matchData.length; ++i) {
if ((typeof matchData[i] == 'string') && (matchData[i] != '')) {
patternArray[index] = matchData[i];
index++;
}
}
if (patternArray[patternArray.length - 1] == '+') {
familyMatch = false;
patternArray.length--;
} else {
if (patternArray[patternArray.length - 1] == '*') {
patternArray.length--;
}
}
var list = deployJava.getJREs();
for (var i = 0; i < list.length; ++i) {
if (deployJava.compareVersionToPattern(list[i], patternArray, familyMatch)) {
return true;
}
}
return false;
} else {
alert('Invalid versionPattern passed to versionCheck: ' + versionPattern);
return false;
}
},
isWebStartInstalled: function (minimumVersion) {
var browser = deployJava.getBrowser();
if ((browser == '?') || ('Safari' == deployJava.browserName2)) {
return true;
}
if (minimumVersion == 'undefined' || minimumVersion == null) {
minimumVersion = '1.4.2';
}
var retval = false;
var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?$";
var matchData = minimumVersion.match(regex);
if (matchData != null) {
retval = deployJava.versionCheck(minimumVersion + '+');
} else {
if (deployJava.debug) {
alert('Invalid minimumVersion argument to isWebStartInstalled(): ' + minimumVersion);
}
retval = deployJava.versionCheck('1.4.2+');
}
return retval;
},
getJPIVersionUsingMimeType: function () {
for (var i = 0; i < navigator.mimeTypes.length; ++i) {
var s = navigator.mimeTypes[i].type;
var m = s.match(/^application\/x-java-applet;jpi-version=(.*)$/);
if (m != null) {
deployJava.firefoxJavaVersion = m[1];
if ('Opera' != deployJava.browserName2) {
break;
}
}
}
},
isPluginInstalled: function () {
var plugin = deployJava.getPlugin();
if (plugin && plugin.jvms) {
return true;
} else {
return false;
}
},
isPlugin2: function () {
if (deployJava.isPluginInstalled()) {
if (deployJava.versionCheck('1.6.0_10+')) {
try {
return deployJava.getPlugin().isPlugin2();
} catch (err) {}
}
}
return false;
},
allowPlugin: function () {
deployJava.getBrowser();
var ret = ('Safari' != deployJava.browserName2 && 'Opera' != deployJava.browserName2);
return ret;
},
getPlugin: function () {
deployJava.refresh();
var ret = null;
if (deployJava.allowPlugin()) {
ret = document.getElementById('deployJavaPlugin');
}
return ret;
},
compareVersionToPattern: function (version, patternArray, familyMatch) {
var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?$";
var matchData = version.match(regex);
if (matchData != null) {
var index = 0;
var result = new Array();
for (var i = 1; i < matchData.length; ++i) {
if ((typeof matchData[i] == 'string') && (matchData[i] != '')) {
result[index] = matchData[i];
index++;
}
}
var l = Math.min(result.length, patternArray.length);
if (familyMatch) {
for (var i = 0; i < l; ++i) {
if (result[i] != patternArray[i]) return false;
}
return true;
} else {
for (var i = 0; i < l; ++i) {
if (result[i] < patternArray[i]) {
return false;
} else if (result[i] > patternArray[i]) {
return true;
}
}
return true;
}
} else {
return false;
}
},
getBrowser: function () {
if (deployJava.browserName == null) {
var browser = navigator.userAgent.toLowerCase();
if (deployJava.debug) {
alert('userAgent -> ' + browser);
}
if (browser.indexOf('msie') != -1) {
deployJava.browserName = 'MSIE';
deployJava.browserName2 = 'MSIE';
} else if (browser.indexOf('iphone') != -1) {
deployJava.browserName = 'Netscape Family';
deployJava.browserName2 = 'iPhone';
} else if (browser.indexOf('firefox') != -1) {
deployJava.browserName = 'Netscape Family';
deployJava.browserName2 = 'Firefox';
} else if (browser.indexOf('chrome') != -1) {
deployJava.browserName = 'Netscape Family';
deployJava.browserName2 = 'Chrome';
} else if (browser.indexOf('safari') != -1) {
deployJava.browserName = 'Netscape Family';
deployJava.browserName2 = 'Safari';
} else if (browser.indexOf('mozilla') != -1) {
deployJava.browserName = 'Netscape Family';
deployJava.browserName2 = 'Other';
} else if (browser.indexOf('opera') != -1) {
deployJava.browserName = 'Netscape Family';
deployJava.browserName2 = 'Opera';
} else {
deployJava.browserName = '?';
deployJava.browserName2 = 'unknown';
}
if (deployJava.debug) {
alert('Detected browser name:' + deployJava.browserName + ', ' + deployJava.browserName2);
}
}
return deployJava.browserName;
},
testUsingActiveX: function (version) {
var objectName = 'JavaWebStart.isInstalled.' + version + '.0';
if (!ActiveXObject) {
if (deployJava.debug) {
alert('Browser claims to be IE, but no ActiveXObject object?');
}
return false;
}
try {
return (new ActiveXObject(objectName) != null);
} catch (exception) {
return false;
}
},
testForMSVM: function () {
var clsid = '{08B0E5C0-4FCB-11CF-AAA5-00401C608500}';
if (typeof oClientCaps != 'undefined') {
var v = oClientCaps.getComponentVersion(clsid, "ComponentID");
if ((v == '') || (v == '5,0,5000,0')) {
return false;
} else {
return true;
}
} else {
return false;
}
},
testUsingMimeTypes: function (version) {
if (!navigator.mimeTypes) {
if (deployJava.debug) {
alert('Browser claims to be Netscape family, but no mimeTypes[] array?');
}
return false;
}
for (var i = 0; i < navigator.mimeTypes.length; ++i) {
s = navigator.mimeTypes[i].type;
var m = s.match(/^application\/x-java-applet\x3Bversion=(1\.8|1\.7|1\.6|1\.5|1\.4\.2)$/);
if (m != null) {
if (deployJava.compareVersions(m[1], version)) {
return true;
}
}
}
return false;
},
testUsingPluginsArray: function (version) {
if ((!navigator.plugins) || (!navigator.plugins.length)) {
return false;
}
var platform = navigator.platform.toLowerCase();
for (var i = 0; i < navigator.plugins.length; ++i) {
s = navigator.plugins[i].description;
if (s.search(/^Java Switchable Plug-in (Cocoa)/) != -1) {
if (deployJava.compareVersions("1.5.0", version)) {
return true;
}
} else if (s.search(/^Java/) != -1) {
if (platform.indexOf('win') != -1) {
if (deployJava.compareVersions("1.5.0", version) || deployJava.compareVersions("1.6.0", version)) {
return true;
}
}
}
}
if (deployJava.compareVersions("1.5.0", version)) {
return true;
}
return false;
},
compareVersions: function (installed, required) {
var a = installed.split('.');
var b = required.split('.');
for (var i = 0; i < a.length; ++i) {
a[i] = Number(a[i]);
}
for (var i = 0; i < b.length; ++i) {
b[i] = Number(b[i]);
}
if (a.length == 2) {
a[2] = 0;
}
if (a[0] > b[0]) return true;
if (a[0] < b[0]) return false;
if (a[1] > b[1]) return true;
if (a[1] < b[1]) return false;
if (a[2] > b[2]) return true;
if (a[2] < b[2]) return false;
return true;
},
enableAlerts: function () {
deployJava.browserName = null;
deployJava.debug = true;
},
writePluginTag: function () {
var browser = deployJava.getBrowser();
if (browser == 'MSIE') {
document.write('<' + 'object classid="clsid:CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA" ' + 'id="deployJavaPlugin" width="0" height="0">' + '<' + '/' + 'object' + '>');
} else if (browser == 'Netscape Family' && deployJava.allowPlugin()) {
deployJava.writeEmbedTag();
}
},
refresh: function () {
navigator.plugins.refresh(false);
var browser = deployJava.getBrowser();
if (browser == 'Netscape Family' && deployJava.allowPlugin()) {
var plugin = document.getElementById('deployJavaPlugin');
if (plugin == null) {
deployJava.writeEmbedTag();
}
}
},
writeEmbedTag: function () {
var written = false;
if (navigator.mimeTypes != null) {
for (var i = 0; i < navigator.mimeTypes.length; i++) {
if (navigator.mimeTypes[i].type == deployJava.mimeType) {
if (navigator.mimeTypes[i].enabledPlugin) {
document.write('<' + 'embed id="deployJavaPlugin" type="' + deployJava.mimeType + '" hidden="true" />');
written = true;
}
}
}
if (!written) for (var i = 0; i < navigator.mimeTypes.length; i++) {
if (navigator.mimeTypes[i].type == deployJava.oldMimeType) {
if (navigator.mimeTypes[i].enabledPlugin) {
document.write('<' + 'embed id="deployJavaPlugin" type="' + deployJava.oldMimeType + '" hidden="true" />');
}
}
}
}
},
do_initialize: function () {
deployJava.writePluginTag();
if (deployJava.locale == null) {
var loc = null;
if (loc == null) try {
loc = navigator.userLanguage;
} catch (err) {}
if (loc == null) try {
loc = navigator.systemLanguage;
} catch (err) {}
if (loc == null) try {
loc = navigator.language;
} catch (err) {}
if (loc != null) {
loc.replace("-", "_")
deployJava.locale = loc;
}
}
}
};
deployJava.do_initialize();
But I've read regarding this code:
...if you have both a Sun JRE and
MSJVM installed, the toolkit will
report the Sun JRE version even if
it's disabled and the browser will
actually run MSJVM...
The second problem with that code is that it retrieves a list of the installed JREs, and I only care about the one that will open the Applet I need to deploy inside the browser.
Does someone knows a pure js method to get the version of Java that would run in the browser if I try load an Applet?