faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

117 of 145 people (81%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

how to invoke the save dialog box when clicking in the link

Apr 5th, 2006 12:06
jsWalter, nizeem nizar,


NOTE: 4/5/06
The solution below only works for IE 5.x
I do not have a solution for IE 6.x nor Netscape/Mozilla
jsWalter
=====================
I created this bit of demo code for printing, but it also works for 
Save, Save As, etc.
Hope this helps.
Walter
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Untitled</title>
</head>
<script language="javascript">
// ====================================================================
// Original post: Unkown person - I lost my notes on who did this first
//                Unkown source
// Modified by:   Walter Torres <walter@torres.ws> [www.torres.ws]
//                2021/04/29
//                I found the secret to remove the prompt!
//                Original post did not have this gem to it.
//
// This accesses a built-in Windows command that can perform Magic!
// And yes, this is a Windows ONLY solution.
// In fact, it only works in IE. :(
//
// This still doesn't work with Frames!  :(
//
//          INPUT: intOLEcmd   = integer between 1 and 37, only a few 
are of use
//                 intOLEparam = parameter integer for function - 
optional
//         OUTPUT: none
//   DEPENDANCIES: none
//
//           NOTE: intOLEparam is not optional in the Object call,
//                 I just made it optional here to make life easier.
//                 All command values use '1' execept print, thus my 
reasoning.
//
//        EXAMPLE: // This prints given window/frame WITHOUT prompt!
//                 objWinName.ieExecWB(6, -1)
//
//                 // This prints given window/frame WITH prompt!
//                 objWinName.ieExecWB(6)
// 	               // This will display the Print Preview window
//                 objWinName.ieExecWB(7)
//
//         VALUES: intOLEcmd has these possible values
//                 OLECMDID_OPEN         = 1
//                 OLECMDID_NEW          = 2    warning, this kills IE 
windows!
//                 OLECMDID_SAVE         = 3
//                 OLECMDID_SAVEAS       = 4
//                 OLECMDID_SAVECOPYAS   = 5    note: does nothing in IE
//                 OLECMDID_PRINT        = 6    note: give '-1' as 
param - no prompt!
//                 OLECMDID_PRINTPREVIEW = 7
//                 OLECMDID_PAGESETUP    = 8
//                          Others have no use in IE
function ieExecWB( intOLEcmd, intOLEparam )
{
	// Create OLE Object
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	// Place Object on page
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	// if intOLEparam is not defined, set it
	if ( ( ! intOLEparam ) || ( intOLEparam < -1 )  || ( 
intOLEparam > 1 ) )
		intOLEparam = 1;
	// Execute Object
	WebBrowser1.ExecWB( intOLEcmd, intOLEparam );
	// Destroy Object
	WebBrowser1.outerHTML = "";
}
</script>
<script>
function saveAsMe (filename)
{
	document.execCommand('SaveAs',null,filename)
}
</script>
<body>
This is so cool!!!!!!!!!!!!
<p>
<input type=button value="print preview" onclick="window.ieExecWB(7);">
<input type=button value="page setup" onclick="window.ieExecWB(8);">
<p>
<input type=button value="print page w Prompt" onclick="window.ieExecWB
(6);">
<input type=button value="print page w/o Prompt" 
onclick="window.ieExecWB(6, -1);">
<p>
<input type=button value="Save As" onclick="saveAsMe('ww.txt');">
<input type=button value="Save Copy" onclick="window.ieExecWB(5);">
</body>
</html>