function test(text)
{
    //alert("Testing private key export!!");
    download("GFG.json", text);
    return "111";
}

function download(file, text) {

    //creating an invisible element
    var element = document.createElement('a');
    element.setAttribute('href','data:text/plain;charset=utf-8,'+encodeURIComponent(text));
    element.setAttribute('download', file);

    // Above code is equivalent to
    // <a href="path of file" download="file name">

    document.body.appendChild(element);

    //onClick property
    element.click();

    document.body.removeChild(element);
}