摘要:JavaScript - 網址檔案下載
<script>
var Download = {
click : function(node) {
var ev = document.createEvent("MouseEvents");
ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
return node.dispatchEvent(ev);
},
link : function(data, name){
var a = document.createElement('a');
a.download = name || self.location.pathname.slice(self.location.pathname.lastIndexOf('/')+1);
a.href = data || self.location.href;
return a;
}
};
Download.save = function(url, name){
this.click(
this.link( url , name)
);
};
</script>
<form id="form1" name="form1" method="POST" >
網 址:<input type="text" id="file_url" size="100" value=""><br/>
檔案名稱:<input type="text" id="filename" size="50" value=""></br>
<button onclick="Download.save($('#file_url').val(),$('#filename').val());return false;">存檔</button>
</form>