Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在当前页面中下载pdf不起作用?_Javascript_Jquery_Html_Anchor_Href - Fatal编程技术网

Javascript 在当前页面中下载pdf不起作用?

Javascript 在当前页面中下载pdf不起作用?,javascript,jquery,html,anchor,href,Javascript,Jquery,Html,Anchor,Href,目前,下面的代码运行良好,但我希望PDF下载在同一页上,而不是在窗口中打开(相同/不同)。 有可能吗?如果有任何帮助,我们将不胜感激 <script> $(document).ready(function () { setTimeout(function () { $('a[href]#hide-link').each(function () { var href = this.href; $(t

目前,下面的代码运行良好,但我希望PDF下载在同一页上,而不是在窗口中打开(相同/不同)。 有可能吗?如果有任何帮助,我们将不胜感激

<script>
$(document).ready(function () {
    setTimeout(function () {

          $('a[href]#hide-link').each(function () {
              var href = this.href;

              $(this).removeAttr('href').css('cursor', 'pointer').click(function () {
                  if (href.toLowerCase().indexOf("#") >= 0) {

                  } else {
                      window.open(href, '_self');


                  }
              });
          });

    }, 500);
});
</script>

$(文档).ready(函数(){
setTimeout(函数(){
$('a[href]#隐藏链接')。每个(函数(){
var href=this.href;
$(this).removeAttr('href').css('cursor','pointer')。单击(函数(){
if(href.toLowerCase().indexOf(“#”)>=0{
}否则{
window.open(href,'u self');
}
});
});
}, 500);
});
HTMl:

<a href="example.pdf" download="example" id="hide-link">Download</a>

$(document).ready(function () {
            setTimeout(function () {

                $('a[href]#hide-link').each(function () {
                    var href = this.href;
                    $(this).removeAttr('href').css('cursor', 'pointer').click(function () {
                        if (href.toLowerCase().indexOf("#") >= 0) {

                        } else {
                            window.location = href;
                        }
                    });
                });

            }, 500);
        });