I'd suggest window. If it's a download, there will be no window and you will get your file. If there is a or something, the user will see it in a new window hence, their work will not be bothered, but they will still get an error message.
Why are you making server side stuff when all you need is to redirect browser to different window. Here is code that parses? If you have jQuery in your project definitely remove those window. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 12 years, 11 months ago. Active 4 years, 9 months ago. Viewed k times.
Let's say I have download links for files on my site. Improve this question. Baptiste L 7 1 1 silver badge 6 6 bronze badges. Vasil Vasil Add a comment. Active Oldest Votes. We do it that way: First add this script. Improve this answer. This requires a little intermediate knowledge of the JavaScript to work and in this example a Axios library will be used. Skip to content. Change Language. Related Articles. Table of Contents. Save Article.
Both of this methods are not ideal. During investigation of the question some interesting solutions were found.
Together they seems to be perfect solution for JavaScript files downloading. Click on link method also have not such problem as empty window in Chrome or Safari.
However we can create hidden link and programmatically click on it by dispatching new mouse event. What else can annoy user? And it can be avoided by using HTML5 download attribute. This attribute will tell browser that virtual link we created is aimed for download only.
Project on GitHub. I checked and found, it will work on button click via writing onclick event to Anchor tag or Input button. Be sure to serve up the file without a no-cache header! I think this will work for you. But visitors are easy if they got something in seconds without spending more time and hence they will also again visit your site.
Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New.
0コメント