如何获取在Javascript中使用HTML5输入类型=文件选择的internet快捷方式的url?
我想获得YouTub视频的网址(URL/URI),用户已将其作为internet快捷方式链接文件(*.windows pc上的URL或mac上的什么?)保存到他们的计算机桌面上,我想使用Chrome、IE 11或更高版本、Edge或FireFox实现这一点,但Edge遇到了问题 我编写了以下代码,在Chrome、IE 11和Firefox中运行良好,可以在这个代码笔中演示: 以下是代码笔中的输入语句和脚本代码:如何获取在Javascript中使用HTML5输入类型=文件选择的internet快捷方式的url?,javascript,url,readfile,Javascript,Url,Readfile,我想获得YouTub视频的网址(URL/URI),用户已将其作为internet快捷方式链接文件(*.windows pc上的URL或mac上的什么?)保存到他们的计算机桌面上,我想使用Chrome、IE 11或更高版本、Edge或FireFox实现这一点,但Edge遇到了问题 我编写了以下代码,在Chrome、IE 11和Firefox中运行良好,可以在这个代码笔中演示: 以下是代码笔中的输入语句和脚本代码: <!-- Get internet shortcut/link file -
<!-- Get internet shortcut/link file -->
<input type="file" id="inputFile" accept=".url" />
<!-- The following script validates the selected file and
extracts the url -->
<script>
const inputFile = document.getElementById( 'inputFile' );
const outputTextarea = document.getElementById( 'outputTextarea' );
const fileReader = new FileReader();
fileReader.onload = function( event ) {
const file = event.target.result;
const allLines = file.split( /\r\n|\n/ );
outputTextarea.value = inputFile.files[ 0 ].name;
// Reading line by line
allLines.forEach( function( line ) {
if( line.substring( 0, 4 ) === 'URL=' ) {
outputTextarea.value += '\n' + line.substring( 4 );
}
} );
};
fileReader.onerror = function( event ) {
alert( event.target.error.name );
};
inputFile.onchange = function( event ) {
// If the file is of the right type, then read its contents ...
if( inputFile.files[ 0 ].name.substr( -4, 4 ) === '.url' ) {
fileReader.readAsText( event.target.files[ 0 ] );
}
else {
outputTextarea.value = 'The selected file is not an internet shortcut link file: ' + inputFile.files[ 0 ].name;
}
}
</script>
const inputFile=document.getElementById('inputFile');
const outputTextarea=document.getElementById('outputTextarea');
const fileReader=new fileReader();
fileReader.onload=函数(事件){
const file=event.target.result;
const allLines=file.split(/\r\n |\n/);
OutputExtArea.value=inputFile.files[0]。名称;
//逐行阅读
allLines.forEach(函数(行){
if(第行子字符串(0,4)='URL='){
OutputExtArea.value+='\n'+行.子字符串(4);
}
} );
};
fileReader.onerror=函数(事件){
警报(event.target.error.name);
};
inputFile.onchange=函数(事件){
//如果文件类型正确,则读取其内容。。。
if(inputFile.files[0].name.substr(-4,4)=='.url'){
fileReader.readAsText(event.target.files[0]);
}
否则{
OutputExtArea.value='所选文件不是internet快捷链接文件:'+inputFile.files[0]。名称;
}
}
但是,在Edge中,“选择文件”对话框不会筛选internet快捷方式,选择快捷方式有时只会返回扩展名为.url的文件。而是按照快捷方式操作并返回网页内容
有没有办法让Edge像其他浏览器一样工作并返回选定的url文件
这个问题的第二部分是:我不知道Mac上用于internet快捷方式的文件类型,也不知道文件结构,因此我无法提取实际的web地址
有谁知道更多关于苹果电脑,请给我这个信息或链接到它
谢谢。这是更大应用程序的一部分吗?我对这方面的用例很好奇,因为仅仅提取一个字符串似乎需要做很多工作。是的,我将YouTube地址与图片以及其他信息一起存储在一个应用程序中,该应用程序创建了一个“墙”,其他人可以查看,有点像FaceBook,但实际上非常不同。