开发者

jquery after() doesnt work properly when creating a url in internet explorer

开发者 https://www.devze.com 2023-01-04 17:35 出处:网络
so I have a function that exports some data async via asp.net and displays a URL on the page to download the exported file, it works perfectly in chrome. but in internet explorer, it displays the link

so I have a function that exports some data async via asp.net and displays a URL on the page to download the exported file, it works perfectly in chrome. but in internet explorer, it displays the link, but the link is not click-able, it just renders as plain text!

The data returned Export.aspx contains the URL to the exported file. (Remember it works perfectly in chrome)

function doExport(oper) {
                var pass = prompt("Please enter the Admin password", "none");
                if (hex_md5(pass) == "592e19c40272fcc615079c346a18d140") {
                    $("#btnExportStat").attr('disabled', 'disabled');
                    $("#btnExportView").attr('disabled', 'disabled');
                    $("#btnAfter").after("<p id='loading'>Please wait...<img src='images/loading.gif' /></p>");
                    jQuery.post("Export.aspx", { "type": oper }, function (data) {
                        $('#loading').remove();
                        if (data.toString() == "error") {
                            $('#btnAfter').a开发者_开发问答fter("<b>There was an error</b>");
                        } else {
                            var d = new Date();
                            var curr_hour = d.getHours();
                            var curr_min = d.getMinutes();
                            var sec = d.getSeconds();
          ========>>>//$('#btnAfter').after("<a href='" + data + "'>" + "Click here to Download File(" + curr_hour + ":" + curr_min + ":" + sec + ")</p>");
                            $("#btnExportStat").attr('disabled', '');
                            $("#btnExportView").attr('disabled', '');
                        }
                    });
                } else {
                alert("Incorrect password");
                }
            }


You start with <a> but end with </p> ...

Call me old-fashioned but I generally add markup differently:

$('#btnAfter').after($("<a/>")
  .attr('href', data)
  .text("Click here to Download File(" + curr_hour + ":" + curr_min + ":" + sec + ")")
);

It's a little harder to make such typos then.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号