0

I have created a grid-view with bound data and then I created a simple java script method to copy the whole grid-view on the clipboard, problem is this java script is only working on IE and not on 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>
Ozzman1893
  • 43
  • 6
  • 2
    Possible duplicate of [Copy image to Clipboard not working in Firefox & Chrome](https://stackoverflow.com/questions/10221298/copy-image-to-clipboard-not-working-in-firefox-chrome) – James Thorpe Aug 23 '17 at 08:05
  • this one is about copying text not images – Ozzman1893 Aug 23 '17 at 08:07
  • 1
    Same underlying issue though - `createControlRange` is IE only. Follow through to the duplicate of that duplicate for a comprehensive "how to use the clipboard" answer that's been kept up to date with modern methods. – James Thorpe Aug 23 '17 at 08:08

0 Answers0