Q: Cannot specify the filename of exported excel file through javascript and php I am using this function to export html tables to excel files.
Everything is working great except the filename....
When I am using this function the file name become something like FFE2dfA and its diferrent each time I am executing it...
Can you help me please how to specify the filename?
This is the function:
    function toExcel(){
    var tab_text="<html xmlns='http://www.w3.org/1999/xhtml' lang='el-GR' lang='el-GR'>";
    var tab_text=tab_text+"<?php Response.AddHeader("Content-Disposition", "inline;filename=filename.xls") ?>";
    var tab_text=tab_text+"<meta http-equiv='content-type'  content='text/plain; charset=UTF-8'/>";
    var tab_text=tab_text+"<table border='2px'><tr bgcolor='#87AFC6'>";
    var textRange; var j=0;
    tab = document.getElementById('table_results'); // id of table

    for(j = 0 ; j < tab.rows.length ; j++) 
    {     
        tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
    }

    tab_text=tab_text+"</table>";
    tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");
    tab_text= tab_text.replace(/<img[^>]*>/gi,""); 
    tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); 
    tab_text= tab_text.replace(/<button[^>]*>|<\/button>/gi, ""); 

    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE "); 

    sa = window.open('data:application/vnd.ms-excel,filename=filename.xls,' + encodeURIComponent(tab_text));  

    return (sa);
   }


A: here in your code:
var tab_text=tab_text+"<?php Response.AddHeader("Content-Disposition", "inline;filename=filename.xls") ?>";

everything looks good, until javascript reaches Content-Disposition
 which confuses javascript, it expects either an operator like + or an end of the line ; indicator, instead there is an unexpected identifier Content which in javascript's eyes is an stranger! 
I think what you meant is:
"<?php Response.AddHeader(\"Content-Disposition, inline;filename=\"filename.xls\"\") ?>"

