Question

I created a custom control that inherits from PageViewerWebPart.

Now I need to toggle the allowTransparency attribute to = "true" on the rendered iframe to enable background transparency for the page in IE8+.

I wrote some javascript to do it (but it isn't working properly), and there are no exposed methods of the class to add attributes to a nested child element.

The control renders the following hierarchy of code:

<div>
<table>
    <tr>
        <td valign="top">
            <div WebPartID="00000000-0000-0000-0000-000000000000">
                <iframe title="Page Viewer">
                    <div class="UserGeneric">iframe not supported warning</div>
                </iframe>
            </div>
        </td>
    </tr>
</table>
</div>

So here's my javascript:

function setTransparency() {
var divs = document.getElementsByTagName("div");
var element;
var eClass;
var result;

// Get "marked" div (container for fly out)
for (var i = 0; (element = divs[i]) != null; i++) {
    eClass = element.className;
        if (eClass) {
            if (eClass.indexOf("marked") != -1) {
            result = element;
            break;
        }
    }
}

// Find iframe contained within flyout
var ifr = findDescendantIframe(result);

if (ifr != null) {
    ifr.allowTransparency = "true";
}}

// Recursive find of iframe (kind of) - if no children, no return value
function findDescendantIframe(parent) {
if (parent.hasChildNodes()) {
    for (var i = 0; (child = parent.childNodes[i]) != null; i++) {
        if (child.nodeName == "IFRAME") {
            return child;
        }
        return findDescendantIframe(child);
    }
}}

Javascript may not be the answer. Is there any way to do this via C# or maybe there's something wrong with my js?

Was it helpful?

Solution

I resolved this by scrapping the control and writing my own using an HtmlTextWriter object to render the same HTML code, but with the addition of the allowTransparency attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top