You can use data URIs, but there are some limitations. Here is an example based on my answer to an earlier question . The first thing you will notice is that you cannot control the file name, but it works fine in Firefox and Chrome, except for that, but maybe not so well in IE (I haven't tried it).
Assuming you can already generate PGN as a string, the code to create the data URI is pretty simple:
function exportData(data, target) {
var exportLink = document.createElement('a');
exportLink.setAttribute('href', 'data:application/x-chess-pgn;base64,' + window.btoa(data));
exportLink.appendChild(document.createTextNode('sample.pgn'));
document.getElementById(target).appendChild(exportLink);
}
Just set the data with what you are creating and configure the element to hold the link after it is created.
In the future, we will have better solutions for these kinds of problems, but there is no browser support yet.
source
share