简体   繁体   中英

Export table contents to excel not working in IE 8 using jquery

Here, I have tried to export the table contents to excel. It is working fine in Firefox. But it is not working in IE 8. Can someone help me to resolve this problem? I have used jquery here. If it is possible using javascript also, I am ok with that.

<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
        <script>
            $(document).ready(function() {
                $("[id$=excellink]").click(function(e) {
                    alert("$('div[id$=dvData]').html()");
                    window.open('data:application/vnd.ms-excel,' + encodeURIComponent( $('div[id$=dvData]').html()));
                    e.preventDefault();
                });
            });
        </script>
        <body>
            <br/>
            <div id="dvData">
                <table>
                    <tr>
                        <th>Billing System</th>
                        <th>Market Code</th>
                        <th>Payment Amount</th>
                    </tr>
                    <tr>
                        <td>RED</td>
                        <td>222</td>
                        <td>$103.00</td>
                    </tr>
                    <tr>
                        <td>BLUE</td>
                        <td>111</td>
                        <td>$13.00</td>
                    </tr>
                    <tr>
                        <td>GREEN</td>
                        <td>555</td>
                        <td>$143.00</td>  
                    </tr>
                </table>
            </div>
            <br/>
            <input type="button" id="excellink" value="Excel" />

        </body>
    </head>
</html>

Try by adding bellow code specific to IE 8

    <!--[if eq IE 8]>
        <script>
                    $(document).ready(function() {
                        $("[id$=excellink]").click(function(e) {
                            alert("$('div[id$=dvData]').html()");
                            window.open('data:application/vnd.xls,' + encodeURIComponent( $('div[id$=dvData]').html()));
                            e.preventDefault();
                        });
                    });
                </script>
<![endif]-->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM