Share

Enabling Text Selection on CRM Web Resources in Dynamics CRM

When writing a custom web resource that includes ClientGlobalContext.js.aspx on the page, it will add several event handlers to the page including one for onselectstart. Because of this behavior built into ClientGlobalContext, normal text on the page that isn't in text boxes is not selectable. In order to re-enable text selection, add the class ms-crm-Field-Data-Print to each element that you want to be selectable.

<div>
    Account Number: <span class="ms-crm-Field-Data-Print">A38104<span>
</div>

Unfortunately, it doesn't cascade down so you need to add the class at each level to enable selection. In the example below, adding the class to just the div will not work because the text is contained in spans. The class needs to be added to each element for selection to be enabled if selection starts at that element.

<div class="ms-crm-Field-Data-Print">
    <span class="ms-crm-Field-Data-Print">Some selectable text</span>
    <span class="ms-crm-Field-Data-Print">in multiple spans.</span>
</div>

If you want to enable text selection for the entire document, you can use javascript to set _UI_TEXT_SELECTABLE to "1".

<script type="text/javascript">
    var _UI_TEXT_SELECTABLE = "1";
</script>

Both methods for making text selectable work in Dynamics CRM 2011 update rollup 16 and Dynamics CRM 2013 update rollup 2. Note, this approach is not documented in the SDK, so it is not officially supported and may change in the future.