.url是一种Windows中特有的文件格式,通常用于保存Internet上的链接信息,也称为网址文件。实质上,.url文件是一种普通文本文件,其内容以INI格式存储,包含了链接的地址、名称和一些其他的元数据信息。.url文件可以通过双击打开相关的网页或程序,方便用户快速访问互联网资源。
const shortcutBtn = document.createElement('button');
shortcutBtn.innerText = '生成超链接';
shortcutBtn.addEventListener('click', () => {
const blob = new Blob(['[InternetShortcut]\r\nURL=' + window.location.href], { type: 'text/plain' });
const link = document.createElement('a');
link.setAttribute('href', URL.createObjectURL(blob));
link.download = "超链接来了.url";
link.setAttribute('target', '_blank');
link.click();
});
document.body.appendChild(shortcutBtn);