This question brought a new one:
I have a html page and I need it to change the content type when the user press "save" button so the browser prompt to save the file to disk
I've been doing this in the server side to offer "excel" versions of the page ( which is basically a html table )
<c:if test="${page.asExcelAction}">
<%
response.setContentType("application/vnd.ms-excel");
%>
What I'm trying to do now is to do the same, but in the client side with javacript but I can't manage to do it so.
This is what I've got so far:
<html>
<head>
<script>
function saveAs(){
var sMarkup = document.getElementById('content').innerHTML;
//var oNewDoc = document.open('application/vnd.ms-excel');
var oNewDoc = document.open('text/html');
oNewDoc.write( sMarkup );
oNewDoc.close();
}
</script>
</head>
<body>
<div id='content'>
<table>
<tr>
<td>Stack</td>
<td>Overflow</td>
</tr>
</table>
</div>
<input type="button" value="Save as" onClick="saveAs()"/>
</body>
</html>