Saturday, April 10, 2010

Offline IFrames

Not all of your functionality will be possible in CRM Offline mode.  For example you may have some IFrames that require an internet connection.  For these scenarios you would not want to have the browser display an error to the user.  Just hiding the IFrame may not be sufficient enough either as it may confuse your users as to why it disappeared.  A nice solution in this case is to hide the IFrame as well as provide the user with a reason as to why they can't see it.

Here's a function to hide the IFrame and overlay it with div containing a custom message explaining why the user cannot see the IFrame.

function ReplaceOfflineIFrameWithMessage(iFrame, messageText)
{
    if (iFrame)
    {
        iFrame.style.display = "none";

        var messageDiv = document.createElement("div");
        messageDiv.innerText = messageText;
        messageDiv.textAlign = "center";
        messageDiv.style.fontSize = "12px";
        messageDiv.style.color = "red";
        messageDiv.style.border = "1px solid #6699cc";
        messageDiv.style.padding = "20px";

        document.getElementById(iFrame.id + '_d').appendChild(messageDiv);
    }
}

Then you can use the native CRM function IsOnline to see what mode the user is in and then call this function passing in the desired IFrame to hide and the custom message to display.

if (!IsOnline())
    ReplaceOfflineIFrameWithMessage(crmForm.all.IFRAME_TestIframe, "You cannot access this content offline.  Please click 'Go Online' in the Outlook client to access this content.");

Here's an example of how it looks:



No comments:

Post a Comment