使文本可选

时间:2013-05-28 09:27:22

标签: javascript html html5 dynamics-crm-2011 selection

我在CRM 2011工作(编辑:汇总13),我为功能区编写了一个小(dev)帮助器,它在模式弹出窗口中显示当前记录的ID (使用picoModal覆盖任何较重的库,以便我可以嵌入脚本。)

无论如何,CRM中的某些内容(脚本或其他内容)阻止了全局级别的文本选择,使得我的弹出窗口几乎无用,我已经尝试覆盖可以在弹出窗口中禁用文本选择的最明显的东西,包括设置所有特定于浏览器的-foo-user-select: text; css属性,我重置了无法选择的属性,甚至尝试将onselectstart事件重置为return false; 应用弹出窗口将由picoModal动态构建。

picoModal(entityName + ":<div id='info-region' unselectable='off' onselectstart='return true;'  style='user-select: text; -ms-user-select: text; -webkit-user-select: text; -khtml-user-select: text; -moz-user-select: text; -o-user-select: text;'><code><pre>" + str + "</pre></code></div><i>(press [CTRL]+[C] to copy the " + entityName + " entities ID to the clipboard)</i>");

除了我的主要问题,我无法在弹出窗口中选择文本,为简化复制重要数据,我使用一些代码在str有效负载中选择相关文本,以便轻松复制(这是我从SO抄袭的,没有链接了,但如果你知道,请引用作者):

function selectText(entity) {
    var doc = document;
    var text = doc.getElementById(entity);

    if (document.body.createTextRange) { // ms
        var range = document.body.createTextRange();
        range.moveToElementText(text);
        range.select();
    } else if (window.getSelection) { // moz, opera, webkit
        var selection = window.getSelection();
        var range = doc.createRange();
        range.selectNodeContents(text);
        selection.removeAllRanges();
        selection.addRange(range);
    }
}

代码在测试页面(跨浏览器)中工作,但是一旦它在Internet Explorer中上传到CRM 2011,模态弹出窗口中的所有文本都是不可选择的,并且在Firefox中文本是可选择的但是所选范围是未聚焦的当它显示给用户时,所以我假设必须有一些限制文本选择的方法我没有想到或者我没有正确覆盖其中一种已知方法。

2 个答案:

答案 0 :(得分:2)

您可以添加课程&#34; ms-crm-Field-Data-Print&#34;使文字可选。要为整个页面启用文本选择,请设置&#34; window._UI_TEXT_SELECTABLE =&#34; 1&#34 ;;&#34;在javascript中。

http://blog.customereffective.com/blog/2014/05/selectable-text-on-crm-web-resources-with-clientglobalcontext.html

答案 1 :(得分:1)

一种可能的解决方案是使用textarea来保存str变量

以这种方式致电picoModal

picoModal(entityName + "<textarea id='guidarea' readonly rows='1'>" + str + "</textarea><i>(press [CTRL]+[C] to copy the " + entityName + " entities ID to the clipboard)</i>");
document.getElementById('guidarea').focus(); // necessary for Google Chrome
document.getElementById('guidarea').select();

因为是textareaselect()功能足以在多个浏览器中选择文字(使用IE 9,Chrome 27,Firefox 21进行测试)