You can pass the object from your page to the server script using AJAX, like this (jQuery):
var ajax_object // Your object .ajax({ type: "POST", url: "tofile.php", data: ajax_object, });
and then write it to the HTML file using the server-side version of the script (example using PHP):
// File: tofile.php $ajax_object // Object, which You have passed using AJAX ob_start(); print_r("<pre>".print_r($ajax_object, true)."</pre>"); $var = ob_get_contents(); ob_end_clean(); $fp = fopen('somefile.htm', 'w'); fputs($fp, $var); fclose($fp);
The result in somefile.htm will look like this:
Some_Object Object ( [some_element] => 123 [some_array] => Array ( [element1] => 456 [element2] => 789 [element3] => 012 ) )
If you are interested in how to save your object in a file using only Javascript, without a server language, then I am afraid this is not possible.
bogatyrjov
source share