gpt4 book ai didi

javascript - 通过输入文件值在新浏览器选项卡中打开文件

转载 作者:行者123 更新时间:2023-11-28 16:48:34 25 4
gpt4 key购买 nike

我想在新的浏览器选项卡中打开文件进行预览。

<input id="myinput" type="file" onchange="oninputfileselected(this);"/>   
function oninputfileselected(obj) {
var inputfile = document.getElementById($(obj).attr('id'));
console.log(inputfile.files);
}

我得到的控制台输出不包含任何可供我打开新选项卡的本地路径。我不确定是否还有其他方法可以做到这一点?谢谢

最佳答案

我能想到的唯一方法是使用 FileReader 读取文件中的数据,然后从中生成 data: 方案 URL,然后打开它带有 window.open 的 URL。

关于javascript - 通过输入文件值在新浏览器选项卡中打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60260371/

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