如何自动下载文件而不点击按钮? [英] How can I download a file automatically without click on button?

查看:150
本文介绍了如何自动下载文件而不点击按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写代码,打开一个干净的页面,在打开文件时下载文件。
我的问题是我没有找到如何自动执行。我只找到这个代码:

I am trying to write code that opens a clean page that downloads a file when I open it. My problem is that I didn't find how to do it automatically. I only find this code:

<!DOCTYPE html>
<html>
<body>
<a href="content/file.jpg" download > jpg link </a>
</body>
</html>

推荐答案

不使用后台语言,您可以将此jQuery添加到HTML文档。

Without using a backend language, you can add this jQuery to your HTML document.

<script type="text/javascript">
    $(document).ready(function () {

        $("a").click();

    });
</script>

文档加载后,链接将自动点击。

The link will be automatically clicked as soon as the document has loaded.

这篇关于如何自动下载文件而不点击按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆