一种使这个javascript在chrome上运行的方法

时间:2017-08-23 08:04:50

标签: javascript asp.net google-chrome

我创建了一个带有绑定数据的网格视图,然后我创建了一个简单的java脚本方法来复制剪贴板上的整个网格视图,问题是这个java脚本只能在IE上工作而不能在chrome上工作。 JS:

<script type="text/javascript">
        function CopyGridView() {
            var div = document.getElementById('TestCopy').contentEditable = true;

            var controlRange;
            if (document.body.createControlRange) {
                controlRange = document.body.createControlRange();
                controlRange.addElement(div);
                controlRange.execCommand('Copy');
            }
            div.contentEditable = 'false';
        }
    </script>

的GridView:

<div runat="server" id="gvTaskTableDiv" style="width: auto; height: 300px; overflow: auto; background-color: white">
                                    <div id="TestCopy">
                                        <asp:GridView ID="gvTaskTable" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-actions gridview col-lg-3 col-md-3 col-sm-3 col-xs-12 center-block">
                                            <Columns>
                                                <asp:BoundField HeaderText="Name" DataField="Name" ItemStyle-ForeColor="Black" />
                                                <asp:BoundField HeaderText="Task Description" DataField="TaskDescription" ItemStyle-ForeColor="Black" />
                                                <asp:BoundField HeaderText="Task Status" DataField="TaskStatus" ItemStyle-ForeColor="Black" />
                                                <asp:BoundField HeaderText="Note" DataField="Note" ItemStyle-ForeColor="Black" />
                                            </Columns>
                                        </asp:GridView>
                                        <input id="btnCopyTable" onclick="CopyGridView()" style="position: static" type="button" value="Copy Table" />
                                    </div>
                                </div>
                            </div>

0 个答案:

没有答案