Improvement to responseHTML.js.

Archives of the forum. responseHTML attribute could be improved.

Fri, 09 Nov 2007 06:54:55


Hi, We've made an improvement to responseHTML for when you are dealing with pages that have been created for you and the html is maybe not so good. For the function getBody we've added code to allow for upper case body tags as well as missing end body tags.

  function getBody(content) {

   upperCaseContent = content.toUpperCase();    // to eliminate case sensitivity
	var x = upperCaseContent.lastIndexOf("<BODY");
	if(x == -1) return "";

	x = content.indexOf(">", x);
	if(x == -1) return "";

	var y = upperCaseContent.lastIndexOf("</BODY>");
	if(y == -1) y = upperCaseContent.lastIndexOf("</HTML>");    // If no body then find html
	if(y == -1) y = upperCaseContent.length;    // If no html then just grab everything till end

	var z = content.slice(x + 1, y);   //make sure we grab the original content
	return z;
Hope you find this of use
Fri, 09 Nov 2007 16:58:14


Thanks for your support. We will add it soon.
Thu, 15 Nov 2007 04:45:18


Back again. This time I had a problem because the page I was loading contained forms, 2 to be precise. And while the page loaded perfectly well the forms didn't return anything except the default values. I tracked the problem down there being 2 copies of the page (and 4 forms), one in the hidden div tag and the other in the visible div tag, this meant that I filled out the visible form and the browser got content from the other (yes I'm using document.forms to get to the forms, maybe I should be more explicit there). Anyway here is the change I've made to fix this..

function processHTML(destination, tempStorage) {
    destination.innerHTML = tempStorage.innerHTML;
    tempStorage.innerHTML = "";
..feel free to point out a better way. Note the scroll(0,0); thing is to set scroll bar of the the content window to the top each time a page loads, I think that the code is wrong but FF and IE work.
Thu, 15 Nov 2007 16:24:38


As that has been pointed by an article that was speaking of our article, (I have lost the URL, I'll search it further) there are limitations in the contents of HTML document inserted in this way. Imagesare not always loaded correctly, and probably forms also... In this case you should put the data in a PHP script and insert it in both HTML pages instead. The article I have cited was speaking of an alternate method with the xml attribute, but I have to found the URL first.
© 2007-2013