简体   繁体   English

Javascript或jQuery:下载并重定向

[英]Javascript or jQuery: Download and redirect

Currently some guys programmed this in a HTML page: 目前,有些人在HTML页面中对此进行了编程:

<script>
    location='http://example.com/downloadable.zip';
</script>

They want to redirect the user to another page once the file has started downloading. 一旦文件开始下载,他们希望将用户重定向到另一个页面。 I can only modify this page but not the destination page. 我只能修改此页面,而不能修改目标页面。

What would be a good and clean javascript solution for making a user download the file and once he had accepted (or rejected) it, redirect him to another location? 什么是使用户下载文件并接受(或拒绝)文件并将其重定向到另一个位置的好又干净的javascript解决方案? The solution may be jQuery code 解决方案可能是jQuery代码

NOTE: The downloading and redirection must be done automatically when accessing the page 注意:在访问页面时,必须自动完成下载和重定向

Perhaps setup a link that calls a function. 也许设置一个调用函数的链接。 The function would in turn then send the download link, and then redirect. 然后,该函数将发送下载链接,然后重定向。

This is just a guess based upon your description, as I don't know the full general setup, but it's what I would do going on what I know. 这只是根据您的描述而做出的猜测,因为我不知道完整的常规设置,但是我将按照我所知道的去做。

This seems like a hack. 这似乎是hack。 Have you tried an HTML meta tag with refresh? 您是否尝试过带有刷新的HTML元标记? Also, you can add a link if the download fails. 另外,如果下载失败,则可以添加链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM