HTML js realizes file download, rar format can be downloaded directly, other formats will be previewed

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script src="http://ajax.aspnetcdn.com/ ajax/jQuery/jquery-1.8.3.min.js"></script>
<script>
$(document).ready(function(){
$("#tt").click(function(){
var form= $("<form>");


   //Set the form state to not display
   form.attr("style","display:none");


   //method attribute set the request type to get
   form.attr("method"," get");


   //The action attribute sets the request path, (if necessary, you can directly follow the path with parameters)
   //For example: htpp://127.0.0.1/test?id=123
   form.attr("action", "SPRING combat.pdf");


   //Place the form in the page (body)
   $("body").append(form);


   //Form submission
   form.submit();
   /* var url="mysqlsjkyy.rar";         var elemIF = document.createElement("iframe");            elemIF.src = url;            elemIF.style.display = "none";            document.body.appendChild (elemIF); */         //Define a form form and send the request through the form form         var form=$("<form>");         //Set the form state to not display         form.attr("style","display: none");         //method attribute sets the request type to post         form.attr("method","post");         //action attribute sets the request path,         //when the request type is post, the path followed by parameters is unavailable         //Parameters can be passed through the input in the form        /* form.attr("action",url);         $("body").append(form);//Place the form in the web





        



















        //Add input tags to the form to pass parameters
        //If there are multiple parameters, you can add multiple input tags
        var input1=$("<input>");
        input1.attr("type","hidden");/ /Set as hidden field
        input1.attr("name","id");//Set parameter name
        input1.attr("value","123");//Set parameter value
        form.append(input1);// Add to the form


        form.submit();//Form submit*/
})
})
</script>
<body>
<p><input type="button" id="tt" value="download"> </script> <body> <p><input type="button" id="tt" value="download">
< /script> body>
</html>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326564750&siteId=291194637