Skip to content

Instantly share code, notes, and snippets.

@evagoras
Last active September 28, 2023 15:05
Show Gist options
  • Save evagoras/dc50350427953afcdd50fcdbf12abaf2 to your computer and use it in GitHub Desktop.
Save evagoras/dc50350427953afcdd50fcdbf12abaf2 to your computer and use it in GitHub Desktop.
Web-based Content Editor using IFrame
<input type="checkbox" onclick="setMode(this.checked)">
function cmdExec(cmd,opt) {
if (isHTMLMode) {
alert("Please uncheck 'Edit HTML'");
return;
}
idContent.document.execCommand(cmd,"",opt);
idContent.focus();
}
<img src="images/editor/Bold.gif" alt="Bold" onClick="cmdExec('bold')">
<iframe id="idContent" width="600" height="280"></iframe>
var isHTMLMode = false
function document.onreadystatechange() {
idContent.document.designMode = "On";
}
function foreColor() {
var arr = showModalDialog("selcolor.asp","", _
"font-family:Verdana; font-size:12; dialogWidth:45em; dialogHeight:24em" );
if (arr != null) cmdExec("ForeColor",arr);
}
<img alt="ForeColor" src="images/editor/fgcolor.gif" onClick="foreColor()">
<%
Dim numID
numID = Request.QueryString("ID")
%>
<iframe width="600" height="280" id="idContent" src="getContent.asp?ID=<%=numID%>"></iframe>
<img src="images/editor/imageLocal.gif" alt="Insert Local Image" onClick="insertImageLocal()">
function insertImageLocal() {
if (isHTMLMode) {
alert("Please uncheck 'Edit HTML'");
return;
}
var sImgSrc = showModalDialog("selectImage.asp","", "dialogHeight: 500px; dialogWidth: 400px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);
}
function setMode(bMode) {
var sTmp;
isHTMLMode = bMode;
if (isHTMLMode) {
sTmp = idContent.document.body.innerHTML;
idContent.document.body.innerText = sTmp;
} else {
sTmp = idContent.document.body.innerText;
idContent.document.body.innerHTML = sTmp;
}
idContent.focus();
}
function SubmitContent() {
if (isHTMLMode) {
alert("Please uncheck 'Edit HTML'");
return (false);
}
document.editor.YOUR_CONTENT.value = idContent.document.body.innerHTML;
document.editor.submit();
}
<form name="editor" method="post" action="submit_editor.asp">
<input name="YOUR_CONTENT" type="hidden" value="">
<input type="button" name="Submit" value="Submit &raquo;" onclick="SubmitContent();">
</form>
<%
Dim strContent
strContent = Request.Form("YOUR_CONTENT")
'write HTML source
Replace(Server.HTMLEncode(strContent), vbcrlf, "<br>")
'or simply render it on the browser
Response.Write(strContent)
%>
<%Option Explicit%>
<%
Dim numID 'unique identifier passed through the IFrame
Dim strContent 'returned HTML source from database
numID = Request.QueryString("ID")
If numID <> "" Then
' do your database query and populate strContent
Response.Write(strContent)
End If
%>
@evagoras
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment