Unable to select the text left in the Iframe beyond the visible area

﹥>﹥吖頭↗ 提交于 2019-12-12 03:20:08

问题


I am using MVC3 and I have an Iframe in my page, and design mode for this Iframe is turned on for editing at run time. while running this in IE9, I am unable to select the text beyond the visible area of the Iframe. For example: if the first 7 lines are visible in my Iframe, then when I scroll to select the content in the 10th line, then the selection does not occur.

<iframe id="RFrame" runat="server" style="width: 900px;"></iframe>

<script type="text/javascript">

    Sys.Application.add_load(PageLoad);

    function PageLoad() {
        var frame = $get('<%=this.RFrame.ClientID%>');
        $get('<%=this.RFrame.ClientID%>').contentDocument.designMode = "on";
        frame.focus();
    }
</script>

Note: this works fine in all other browsers except IE9. issue occurs only when the document mode is set as IE9 by default for bowser mode IE9.

Can anyone let me know the reason for this behavior or how to resolve this?


回答1:


The problem you are facing is caused by setting designMode = "on"

To fix this issue do not set designMode = "on", instead set contentEditable = true.

Example:

var editor = document.getElementById("RFrame");
editorDoc = editor.contentWindow.document;          
var editorBody = editorDoc.body;
editorBody.contentEditable = true;

This will also remove the horizontal scrollbar from the IFRAME displayed by IE9 when compatibility mode is disabled.



来源:https://stackoverflow.com/questions/9063475/unable-to-select-the-text-left-in-the-iframe-beyond-the-visible-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!