A small part of my web site allows a user to enter a warning message that will appear on the login html page.
The message is captured in a textarea input field. Once the form is submitted a Java process replaces any occurences of '\r\n' with </br> and saves the text to a .txt file on the web server.
The login html page then uses a bit of Ajax to retrieve the .txt file and displays the content it if not empty.
This all works perfecty in both IE7 and Firefox 18.0.2.
To allow the user to amend the message I wish to read it from the web server and display it in the same textarea input field. Prior to display I am attempting to replace the </br> with '\r\n'.
This works in Firefox and but IE7 seems to replace the </br> with space. My Javascript code is as follows. Any help would be greatly appreciated.
Code:
var http = createRequestObject();
function createRequestObject() {
var objAjax;
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
objAjax = new ActiveXObject("Microsoft.XMLHTTP");
} else {
objAjax = new XMLHttpRequest();
}
return objAjax;
}
function getWarningMessage(){
var rightNow = new Date();
http.open('get','/warningmessage/warningmessage.txt?' + rightNow.getTime());
http.onreadystatechange = updateNewContent;
http.send(null);
return false;
}
function updateNewContent(){
var warningMessage;
var warningMessageReplace;
if (http.readyState == 4 && http.responseText.length > 0){
warningMessage = http.responseText;
while (warningMessage.search('</br>') > 0) {
warningMessageReplace = warningMessage.replace('</br>','\r\n');
warningMessage = warningMessageReplace;
}
document.getElementById('warningMessage').innerHTML = warningMessage;
}
}