View Full Version : Saving only a portion of webpage into a file

04-29-2006, 11:52 AM
im working on a web application that generates dynamic data. My question is: i want users to be able to save the generated data, but not the whole web page, just a table in the web page that holds this data. I searched and found out that showing a "save as" dialog box is possible with javascript, with a method like: onclick="javascript: document.execCommand('SaveAs','1',null);. However, i coulnd't find out how to change the document object (or is it possible?) or a trick to print just the table of dynamic data. I tried to cover the table with <div id="myData"></div> and use onclick="javascript: myData.execCommand('SaveAs','1',null); but as you might guess, it didn't work and gave this error message: "object doent support this property or method". Indeed i dont have any idea what div tag can and can't do, so it was just a meaningless try. By the way, i want to add that i can't use iframes just because of program design issues.
Anyway, do you have any suggestions?

thanks in advance,
ibrahim saygılı

04-29-2006, 12:05 PM
Can't order a save from a webpage. Put the data in a textbox and add a "select all" button like the links on DD's scripts.

04-29-2006, 12:22 PM
yes, you can. with document.execCommand('SaveAs','1',null); method of javascript.

my question is: can i put a portion of web page into an object in javascript? if so, another solution would be sending that object to a popup window and print the content of popup window. but how?

04-29-2006, 12:41 PM
yes, you can. with document.execCommand('SaveAs','1',null); method of javascript.No, you can't. That's not a Javascript method; it's a JScript method, meaning that it will only work on Internet Explorer (SaveAs, that is; execCommand exists on other browsers).
The second idea is better, and you can use window.print() to print it.
<script type="text/javascript">
function printElement(id) {
var v = window.open();
"<html>" +
"\t<head>" +
"\t\t<title>" +
"Mysite.com :: Printing Window" +
"</title>" +
"\t</head>" +
"\t<body>" +
document.getElementById(id).innerHTML.toString() +
"\t</body>" +

04-29-2006, 12:51 PM
ok i just saw the code.. looking for it

04-29-2006, 01:09 PM
thank you in advance, it seems quite fitting for me.