Index: jsf-api/src/main/resources/jsf.js =================================================================== --- jsf-api/src/main/resources/jsf.js (revision 8415) +++ jsf-api/src/main/resources/jsf.js Tue Aug 24 23:41:32 EEST 2010 @@ -356,21 +356,14 @@ if (element.nodeName.toLowerCase() === "head") { throw new Error("Attempted to replace a head element - this is not allowed."); } else { - var scripts = []; if (isAutoExec()) { temp.innerHTML = src; } else { - // Get scripts from text - scripts = stripScripts(src); - // Remove scripts from text - src = src.replace(/]*>([\S\s]*?)<\/script>/igm,""); temp.innerHTML = src; } } - replaceNode(temp, element); + replaceNode(temp, element); - runScripts(scripts); - }; /** @@ -853,39 +846,35 @@ if (id === "javax.faces.ViewRoot" || id === "javax.faces.ViewBody") { var bodyStartEx = new RegExp("< *body[^>]*>", "gi"); var bodyEndEx = new RegExp("< */ *body[^>]*>", "gi"); - var newsrc; - var docBody = document.getElementsByTagName("body")[0]; - var bodyStart = bodyStartEx.exec(src); - + - if (bodyStart !== null) { // replace body tag - // First, try with XML manipulation - try { - // Get scripts from text - scripts = stripScripts(src); - // Remove scripts from text + // Get scripts from text + scripts = stripScripts(src); + // Remove scripts from text - newsrc = src.replace(/]*>([\S\s]*?)<\/script>/igm, ""); + var newsrc = src.replace(/]*>([\S\s]*?)<\/script>/igm, ""); + var bodyStart = bodyStartEx.exec(newsrc); + if (bodyStart !== null) { // replace body tag + // First, try with XML manipulation + try { elementReplace(getBodyElement(newsrc), docBody); - runScripts(scripts); } catch (e) { // OK, replacing the body didn't work with XML - fall back to quirks mode insert - var srcBody, bodyEnd; // if src contains - bodyEnd = bodyEndEx.exec(src); + var bodyEnd = bodyEndEx.exec(newsrc); + var srcBody; if (bodyEnd !== null) { - srcBody = src.substring(bodyStartEx.lastIndex, - bodyEnd.index); + srcBody = newsrc.substring(bodyStartEx.lastIndex, bodyEnd.index); } else { // can't find the tag, punt - srcBody = src.substring(bodyStartEx.lastIndex); + srcBody = newsrc.substring(bodyStartEx.lastIndex); } - // replace body contents with innerHTML - note, script handling happens within function + // replace body contents with innerHTML elementReplaceStr(docBody, "body", srcBody); - } - - } else { // replace body contents with innerHTML - note, script handling happens within function - elementReplaceStr(docBody, "body", src); + } else { + // replace body contents with innerHTML + elementReplaceStr(docBody, "body", newsrc); } + runScripts(scripts); } else if (id === "javax.faces.ViewHead") { throw new Error("javax.faces.ViewHead not supported - browsers cannot reliably replace the head's contents"); } else {