锚点锚点,同一窗口下载文件 [英] onclick of anchor, download document in same window
问题描述
我想在同一个窗口中提示用户保存数据[它可以是: - image,pdf,excel sheet等]。
I want to prompt user to save data [it could be anything like:- image, pdf, excel sheet etc] in same window.
我不想要使用 HTML5下载选项,因为这对所有浏览器无效。
I don't want to use HTML5 DOWNLOAD option as this is not valid for all the browsers.
例如: -
我想提示用户下载谷歌标志,如下面的代码。
I want to prompt user to download google logo, as per below code.
<a href="https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"> Download Google Logo</a>
但它不会下载Google图标,尽管它将重定向到该链接。
But it will not download Google icon although it will redirect to that link.
请建议!!
根据我的要求,target =_ blank或iframe不会解决我的问题。我想要用户只需在同一页面下载任何文件。
As per my requirement, target="_blank" or iframe will not solve my concern. I want user will simply download any file in the same page.
推荐答案
使用iFrame方法。
Use the iFrame method.
<iframe id="download" hidden><\iframe>
<a href="javascript:document.getElementById('download').src = 'file-path'>whatever<\a>
-EDIT -
-EDIT-
使用iframe方法不会带你到另一个页面。
Using the iframe method will not take you to a different page.
这篇关于锚点锚点,同一窗口下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!