Using HTML5/JavaScript to generate and save a file

后端 未结 17 1767
有刺的猬
有刺的猬 2020-11-21 07:30

I\'ve been fiddling with WebGL lately, and have gotten a Collada reader working. Problem is it\'s pretty slow (Collada is a very verbose format), so I\'m going to start conv

17条回答
  •  旧时难觅i
    2020-11-21 08:01

    OK, creating a data:URI definitely does the trick for me, thanks to Matthew and Dennkster pointing that option out! Here is basically how I do it:

    1) get all the content into a string called "content" (e.g. by creating it there initially or by reading innerHTML of the tag of an already built page).

    2) Build the data URI:

    uriContent = "data:application/octet-stream," + encodeURIComponent(content);
    

    There will be length limitations depending on browser type etc., but e.g. Firefox 3.6.12 works until at least 256k. Encoding in Base64 instead using encodeURIComponent might make things more efficient, but for me that was ok.

    3) open a new window and "redirect" it to this URI prompts for a download location of my JavaScript generated page:

    newWindow = window.open(uriContent, 'neuesDokument');
    

    That's it.

提交回复
热议问题