Skip to main content

How to: Implement a custom Preview popup

The following example illustrates how to implement a custom Preview popup.

function onCloseUp() {
    previewPopup.RefreshContentUrl();
}
function onCustomCommand(commandName) {
    if (commandName == "Preview") {
        previewPopup.Show();
        window.setTimeout("setHtmlInPreviewIFrame()", 800);
    }
}
function setHtmlInPreviewIFrame() {
    var previewIFrameElement = getFrameByIFrameElement(previewPopup.GetContentIFrame());
    var previewIFrameDoc = null;
    if (previewIFrameElement.document)
        previewIFrameDoc = previewIFrameElement.document;
    else
        previewIFrameDoc = previewIFrameElement.contentDocument
        previewIFrameDoc.body.innerHTML = ASPxHtmlEditor1.GetHtml();
    }
function getFrameByIFrameElement(iframeElement) {
    var name = (new Date()).toString();
    iframeElement.contentWindow.name = name;
    var frameIndex = getFrameByWindowName(name);
    return window.frames[frameIndex];
}
function getFrameByWindowName(name) {
    var count = window.top.frames.length;
    for (var i = 0; i < count; i++) {
        if (window.top.frames[i].window.name === name)
        return i;
    }
    return -1;
}