【问题标题】:Export table contents to excel not working in IE 8 using jquery使用jquery将表格内容导出到excel在IE 8中不起作用
【发布时间】:2015-04-10 18:32:08
【问题描述】:

在这里,我尝试将表格内容导出到excel。它在 Firefox 中运行良好。但它在 IE 8 中不起作用。有人可以帮我解决这个问题吗?我在这里使用了 jquery。如果也可以使用 javascript,我可以接受。

<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>

【问题讨论】:

  • “不工作”...您是否遇到任何错误?
  • IE8 是否支持data: URL?我的感觉是没有。
  • @Pointy 我也有同样的想法..哈哈..
  • 来自caniuse: Support in Internet Explorer 8 is limited to images and linked resources like CSS files, not HTML files. Max URI length in IE8 is 32KB.
  • 在 IE 8 中,它正在重定向到新窗口并显示 URL 中表的值..

标签: javascript jquery html firefox internet-explorer-8


【解决方案1】:

尝试添加特定于 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]-->

【讨论】:

    猜你喜欢
    • 2014-05-07
    • 2015-05-22
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多