gpt4 book ai didi

javascript - 支持 IE Javascript/Jquery/Html5 的拖放下载

转载 作者:行者123 更新时间:2023-11-28 10:49:04 25 4
gpt4 key购买 nike

我尝试了可用的拖放下载示例,但问题是它在 Chrome 中工作得很好,但是当您尝试将文件拖放到本地计算机上并打算使用 IE 下载时,它会出现问题。仅下载文件的快捷方式链接。

大家有办法解决这个问题吗?请分享...

我尝试使用以下链接中的代码。 http://www.thecssninja.com/javascript/gmail-dragout

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en-GB">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="author" content="The CSS Ninja">
<meta name="keywords" content="Drag and drop, HTML5, DownloadURL, setData, dataTransfer">
<meta name="description" content="How to create reverse drag and drop functionality like Gmail in Chrome 5 and upwards">
<meta name="robots" content="all">
<meta name="copyright" content="The CSS Ninja">

<link rel="stylesheet" type="text/css" href="_styles.css" media="screen">

<title>Drag a file from a website to your filesystem like Gmail does | The CSS Ninja</title>

</head>
<body>

<div class="container">
<h1>Drag out any of these links to your dekstop</h1>

<a href="Eadui.ttf" id="dragout" class="dragme" draggable="true" data-downloadurl="application/octet-stream:Eadui2.ttf:http://thecssninja.come/demo/gmail_dragout/Eadui.ttf">Font file</a>

<a href="Eadui.ttf" id="dragout2" class="dragme" draggable="true" data-downloadurl="application/pdf:HTML5CheatSheet.pdf:http://thecssninja.come/demo/gmail_dragout/html5-cheat-sheet.pdf">PDF file</a>
</div>

<script type="text/javascript">
var files = [document.getElementById("dragout"),document.getElementById("dragout2"),document.getElementById("dragout3")],
fileDetails = [];

// Some forward thinking, utilise the custom data attribute to extend attributes available.
if(typeof files[0].dataset === "undefined") {
// Grab it the old way
fileDetails[0] = files[0].getAttribute("data-downloadurl");
fileDetails[1] = files[1].getAttribute("data-downloadurl");
} else {
fileDetails[0] = files[0].dataset.downloadurl;
fileDetails[1] = files[1].dataset.downloadurl;
}

files[0].addEventListener("dragstart",function(evt){
evt.dataTransfer.setData("DownloadURL",fileDetails[0]);
},false);
files[1].addEventListener("dragstart",function(evt){
evt.dataTransfer.setData("DownloadURL",fileDetails[1]);
},false);
</script>

</body>
</html>

最佳答案

您的代码在 Chrome、FF、Opera、Safari 和 Microsoft Edge 中运行良好。

为什么要使用 Microsoft no longer supports 的旧浏览器?

我的建议是,因为不再支持告诉您的用户使用 supported browser .

关于javascript - 支持 IE Javascript/Jquery/Html5 的拖放下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36878092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com