下面的代码片段将javascript html添加到页面中。它适用于Chrome和Firefox,但不适用于IE。
xmlHttp.onload = function() {
if (xmlHttp.status === 200) {
var okToComeBack = true;
var responseJson = JSON.parse(xmlHttp.responseText);
var environmentDiv = document.createElement('div');
environmentDiv.setAttribute('class', 'container-environmentmarker');
environmentDiv.innerHTML = '<div class="container-environment"><div class="environment-marker"></div></div>';
document.body.appendChild(environmentDiv);
document.getElementsByClassName(that._config.environmentClass)[0].innerHTML = responseJson.nameOfEnvironment;
document.getElementsByClassName(that._config.environmentMarkerClass)[0].setAttribute('class', that._config.environmentMarkerClass + ' ' + that._config.environmentMarkerClassPrefix + responseJson.colourOfMarker);
if (responseJson.nameOfSite !== undefined) {
document.getElementsByClassName(that._config.siteNameClass)[0].innerHTML = responseJson.nameOfSite;
}
}
};