JavaScript implements a method that controls the opening of a file save as dialog

  • 2020-05-30 19:24:10
  • OfStack

The example in this article describes how JavaScript implements the control of opening file save as dialog box. Share with you for your reference. The details are as follows:

Here, JS opens the image save as dialog box to prompt the user to save the file


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="js/jquery.min.js" type="text/javascript"></script>
<script language="JavaScript">
<!--
function downLoadImage(imagePathURL){
// If the middle IFRAME Does not exist, adds 
if(!document.getElementById("_SAVEASIMAGE_TEMP_FRAME"))
jQuery('<iframe style="display:none;" id="_SAVEASIMAGE_TEMP_FRAME"
name="_SAVEASIMAGE_TEMP_FRAME" onload="_doSaveAsImage();"
width="0" height="0" src="about:blank"></iframe>').appendTo("body");
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!=imagePathURL){
// The image address has changed. Load the image 
document.all._SAVEASIMAGE_TEMP_FRAME.src = imagePathURL;
}else{
// The image address does not change, save as directly 
_doSaveAsImage();
}
}
function _doSaveAsImage(){
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!="about:blank")
document.frames("_SAVEASIMAGE_TEMP_FRAME").document.execCommand("SaveAs");
}
//-->
</script>
</head>
<body>
<input type="button" value="download image" 
onclick="downLoadImage('https://www.ofstack.com/images/logo.gif');">
</body>
</html>

I hope this article is helpful for you to design javascript program.


Related articles: