var downloadAsFile = function(fileName, content) {
var a = document.createElement('a');
a.download = fileName;
a.href = 'data:application/vnd.ms-excel,'+encodeURIComponent(content);
a.click();
};Run Code Online (Sandbox Code Playgroud)
<button type="submit" id="output_button" onclick="downloadAsFile()">Download</button>Run Code Online (Sandbox Code Playgroud)
在下载 excel 文件时,我的屏幕位置向上移动到顶部。所以我希望屏幕位置保持在同一位置。
我知道如果我使用<a>标签,我可以使用“javascript:void(0)” ,但在这种情况下,我不知道如何添加。
有人有任何解决方案或可以通过其他方式解决吗?