Change the content type of the popup
This question brought a new one:
I have a html page and I need to change its content type when the user clicks the Save button so that the browser will prompt to save the file to disk
I was doing this on the server side to offer an "excel" version of the page (which is basically an 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 client side with javacript, but I can't seem to do it.
This is what I have 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>
+2
source to share