PDA

Click to See Complete Forum and Search --> : Save IFRAME contents [Resolved]


mendhak
Jan 12th, 2005, 03:09 AM
I have an IFRAME on my page like this:


<iframe width="642" id="idContent" height="350"></iframe>


Underneath that, I have a submit button.

The user can paste anything into this IFRAME which will most likely be in HTML format. I would like to know how I can access what has been pasted into the IFRAME when submitting, so that I can save it to a database.

I don't know how to access the contents though, I've tried this:



Response.Write(Request("idContent"))



But that doesn't work.

Something tells me that the mechanism behind IFRAMEs is somewhat different. Any pointers would be appreciated. :)

mendhak
Jan 12th, 2005, 04:13 AM
Got it:




function cleanHtml() {
var fonts = idContent.document.body.all.tags("FONT");
var curr;
for (var i = fonts.length - 1; i >= 0; i--) {
curr = fonts[i];
if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;
}
}



function setMode(newMode) {
bTextMode = newMode;
var cont;
if (bTextMode) {
cleanHtml();
cleanHtml();

cont=idContent.document.body.innerHTML;
idContent.document.body.innerText=cont;
} else {
cont=idContent.document.body.innerText;
idContent.document.body.innerHTML=cont;
}

idContent.focus();
}

function HTMLEncode(t) {
var t = t.toString().replace(/&/g, "&amp;").replace(/"/g, "&quot;");
return(t.replace(/</g, "&lt;").replace(/>/g, "&gt;"));
}


function savedocument() {

setMode(1); //switch doc to html mode for save
// document.xyz.hiddenfield1.value=idContent.document.body.innerText;
//HTMLEncode
document.xyz.hiddenfield1.value=HTMLEncode(idContent.document.body.innerText);
setMode(0); //switch doc back to text mode
document.xyz.submit(); // submit form for save
}


To use it... call savedocument() from the button in the form.

Now to more pressing matters...