File: download-blob.html

package info (click to toggle)
python-playwright 1.55.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,728 kB
  • sloc: python: 53,655; javascript: 383; sh: 216; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
  <head>
    <title>Blob Download Example</title>
  </head>
  <body>
    <script>
      const download = (data, filename) => {
      const a = document.createElement("a");
      a.style = "display: none";
      document.body.appendChild(a);
      a.style = "display: none";

      const blob = new Blob([data], { type: "octet/stream" });
      const url = window.URL.createObjectURL(blob);
      a.href = url;
      a.download = filename;
      a.click();
      window.URL.revokeObjectURL(url);
      document.body.removeChild(a);
    };

    const downloadIt = () => {
      download("Hello world", "example.txt");
    }
    </script>
    <a onclick="javascript:downloadIt();">Download</a>
  </body>
</html>