简体   繁体   中英

Get the content of a DIV and save to a file, jQuery/JS or Server-side

In my site I need to get content of one of DIV and save the content to a file.

I'm just wondering whether is there possibility to to do it in jQuery or JS if not do I have to use server based language like PHP.

Or any one got example or tutorial relative this query?

Using jQuery, access the content of the div using .text();

Then use jquery ajax function to POST this to a PHP script. Inside the php script you should open a file stream using fopen() with "w+" permission and then use fwrite() to write the contents into the file.

You can use jQuery's AJAX function to send the information to a script on the server that would create and save the file on the server.

Directly you cant use jQuery or JS to this purpose.

You could also use the HTML5 Filesystem API to save the file in the browser and use a[download] to present the user with a download link. Alternatively, you could skip the Filesystem and just do the latter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM