- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这样的东西:
<a
onClick={e => { getDownloadLink()
.then(url => window.open(url)) }}>Download</a>
getDownloadLink
方法必须先POST
获取url,然后通过window.open(url)
触发下载,但是我发现浏览器会阻止window.open
行为。我怎样才能防止这种情况发生?
我在stackoverflow中看到很多类似的问题,但我仍然没有找到解决我的问题的方法。我发现 aws s3 页面做了类似的事情,该页面不会被浏览器阻止。所以...我认为必须有某种方法来处理这个问题。
最佳答案
不要使用window.open
,只需让浏览器执行它已经知道的 HTML 操作:构建一个链接 anchor ,然后单击它。
// create an temporary, invisible link and open it in a new tab
function openURL(url) {
var a = document.createElement("a");
a.setAttribute("target", "_blank");
a.href = url;
a.style.display = "none";
// you can't click a link unless it's part of the document:
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
通过这种方式,您可以告诉浏览器“以正常方式打开链接”,它会很乐意这样做,而不是阻止历史上用于弹出窗口和其他可疑目的的可疑 API。
关于javascript - 如何打开网址并下载而不被阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52142986/
我正在通过 NodeSchool.io 练习学习 React 和 Express 框架。 我想将所有练习文件存储在具有多个页面的单个应用程序中,例如 索引 索引2 索引3 索引4 .... local
从这里:http://developer.android.com/reference/android/os/AsyncTask.html doInBackground(URL... urls) onP
我最近收到了一封电子邮件,其中包含以下内容(请勿点击!): UNS 这是原始电子邮件的链接:https://gist.github.com/anonymous/16963a230cab0a3a1bc
在 android 中,可以单击带有 URL 的 TextView 以在网络中打开 URL,方法是: android:autoLink="web" 我想做的是捕获这次点击,如果这个 TextView
我在我的网站上以 mysite.anotherdomain.org 的形式实现 Facebook 登录。我在 JavaScript SDK 的文档中做了所有解释,但由于我遇到了一些问题,我想知道错误是
我在 window.location.href 中有响应网址,我需要其中的 error、error_description 和 state 的值 http://localhost:4200/#erro
我正在创建无限加载,意味着当用户到达页面底部/特定 div 时会加载新页面。目前我有这个代码可以在点击时加载新页面。 $("#about").click(function(){ // load
当我们在谷歌引擎中搜索时,它也会显示热门网站标签或链接。就像我们搜索“bing”或“net beans”时一样。 问:它如何显示这些链接。我们是否必须告诉它显示这些链接。 问:它是否与 sitemap
我想从我的网址中获取我的产品。例如: http://www.website.com/product-category/iphone 我想获取 iphone,这对我的代码来说没问题,但我有一个下拉菜单来
我对 Pythonanywhere 完全陌生,我不知道为什么静态文件没有加载...这是我存储 css 和图像的路径,即 static/images/wikiLang.png 等 /static/adm
我正在使用这个正则表达式来验证 youtube 网址。 ^http:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?:\S+)?$ 它很好用。 但我有这个
我刚刚在 gist.github 上传了一个我正在处理的小编码项目,因为它似乎是一次上传几个类的好方法。 我想将某人与我的“要点”联系起来,并在角落里写着: Public Clone URL: git
我正在使用 jQuery 验证引擎来解析我的表单数据: https://github.com/posabsolute/jQuery-Validation-Engine 验证 Twitter URL 的
我有一个 Django 应用程序,它可以在 localhost 上正常工作。即使对于 utf-8 URL 路径也是如此。但是当我在生产中使用它时,它给了我一个错误: 2019-09-01 14:32:
我已经安装了Laravel并开始尝试编写一个应用程序。我在/ app所在的目录中为 Assets 创建了一些目录。但是,当我尝试访问本地主机中的图像时,例如:http://localhost/asse
我们正在寻找一种方法来检查一长串 YouTube 网址,以查找目前私有(private)、已删除或不再可用的视频。我们可以检查状态,但即使视频不再公开可用,URL 也会返回 200。例如这两个: ht
我在 YouTube 上有现场事件,我想在我的网站上播放它。我想将我的事件设为私有(private),获取它的 RTMP 广播 URL 并将其粘贴到我的网站上,在 JWPlayer 中。 那可能吗?
当我在谷歌上搜索我的域时,它会显示我网站上的几个 https 网址,因为谷歌喜欢 https,但出于特殊原因我不想索引 https/ssl 版本。 如何避免这种情况,全世界都只通过 htaccess
我想获取在 Salesforce.com 授权期间作为回调收到的当前 URL。 url 中的数据位于片段部分。 最佳答案 您可以使用 $_SERVER['HTTP_HOST'] 和 $_SERVER[
我正在使用 ionic 创建一个应用程序,其中我使用 iframe 显示 URL。 这是 HTML 代码: 这是 Angular js: $scope.iframeHeight = windo
我是一名优秀的程序员,十分优秀!