[removed] Download data to file from content within the page

后端 未结 8 1556
时光说笑
时光说笑 2020-12-13 14:35

setting is the following: I have a homepage where I display a diagram that has been constructed using comma seperated values from within the page. I\'d like to give users th

8条回答
  •  抹茶落季
    2020-12-13 14:44

    Update:

    Time certainly changes things ;-) When I first answered this question IE8 was the latest IE browser available (Nov 2010) and thus there was no cross browser way to accomplish this without a round trip to the server, or using a tool requiring Flash.

    @Zectburno's answer will get you what you need now, however for historical context be aware of which IE browsers support which feature.

    • btoa() is undefined in IE8 and IE9
    • Blob is available in IE10+

    Be sure to test in the browsers you need to support. Even though the Blob example in the other answer should work in IE10+ it doesn't work for me just clicking the link (browser does nothing, no error)... only if I right click and save target as "file.csv" then navigate to the file and double-click it can I open the file.

    Test both approaches (btoa/Blob) in this JSFiddle. (here's the code)

    
    
    
    
    
      Download CSV (via btoa)
      
      
    Download CSV (via Blob)

    Original Answer:

    I don't think there is an option available for this.

    I would just adjust your code such that if Flash 10+ is detected (93% saturation as of September 2009) on the user's system, provide the Downloadify option, otherwise fallback to a server-side request.

提交回复
热议问题