Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save page

Status
Not open for further replies.

jebo100

Technical User
May 11, 2007
52
PH


<a href="" onclick="Javascript: window.print()">Print this page</a>

the above prints the current page.

is there a way to save the current page to my local hard drive?
ex:
<a href="" onclick="Javascript: window.Save????()">Save this page</a>

thanks....




JEBO
4saledavao
 


i have tried "execCommand".
but i needed it to work with other browsers too.

thanks a lot for your reply...


JEBO
4saledavao
 
This is how you do it cross-browser. On the moz-based block, you might need to know a bit of xul to understand in order to script; but operational-wise it does not need any knowledge of it. It just differs from ie now by asking explicitly the xpconnect privilege from the user. The user can deny it, sure. It can be granted on one-time-basis. (Do not click on the remember checkbox and you're remaining safe.) The reason is that by default that privilege is denied (for good reason, and I am not suggesting to switch it permanently to allow.)

The demo is no-nonsense free from artificial irrelevance and well-focused.
[tt]
<html>
<head>
<title>xbs_saveas_gt</title>
<script type="text/javascript">
function go_saveas() {
if (!!window.ActiveXObject) {
document.execCommand("SaveAs");
} else if (!!window.netscape) {
var r=document.createRange();
r.setStartBefore(document.getElementsByTagName("head")[0]);
var oscript=r.createContextualFragment('<script id="scriptid" type="application/x-javascript" src="chrome://global/content/contentAreaUtils.js"><\/script>');
document.body.appendChild(oscript);
r=null;
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
saveDocument(document);
} catch (e) {
//no further notice as user explicitly denied the privilege
} finally {
var oscript=document.getElementById("scriptid"); //re-defined
oscript.parentNode.removeChild(oscript);
}
}
}
</script>
</head>
<body>
<a href="#" onclick="go_saveas();return false">save the document</a><br />
</body>
</html>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top