[英]How to open page in new Tab without button click in vueJs
I want to open the page link in a new tab after Axios response success, I have googled the solution about it but the browser keeps blocking popup.我想在 Axios 响应成功后在新选项卡中打开页面链接,我已经搜索了有关它的解决方案,但浏览器一直阻止弹出窗口。 I have tried the below one but not getting work and not supported in all browsers
我已经尝试了下面的一个,但没有得到工作,并且在所有浏览器中都不支持
let newTab = window.open(); newTab.location.href = url;
_blank
can help you opening new window. _blank
可以帮助您打开新窗口。 check out the documentation of window.open function on w3school.查看 w3school 上 window.open 函数的文档。 https://www.w3schools.com/jsref/met_win_open.asp
https://www.w3schools.com/jsref/met_win_open.asp
But for security reasons, browsers block such pop-ups.但出于安全原因,浏览器会阻止此类弹出窗口。 This is a default and desired behaviour from user security point of view.
从用户安全的角度来看,这是默认和期望的行为。 You can override this setting using below solution.
您可以使用以下解决方案覆盖此设置。 https://blog.getadblock.com/how-to-disable-pop-up-blockers-in-every-browser-a1cccbae53e7
https://blog.getadblock.com/how-to-disable-pop-up-blockers-in-every-browser-a1cccbae53e7
您可以使用_blank
值将其指定为第二个参数:
let newTab = window.open(url,'_blank');
@Dhruti if all else fails you can still have a button click trigger the new tab, just make th button hidden and trigger a click action with JavaScript. @Dhruti 如果所有其他方法都失败了,您仍然可以单击按钮触发新选项卡,只需隐藏按钮并使用 JavaScript 触发单击操作。 Give the button an id or ref="somename" in Vue, and a class.
在 Vue 中给按钮一个 id 或 ref="somename",以及一个类。 Set it's
opacity: 0;
设置它的
opacity: 0;
and position it somewhere on the page where it's unnoticed.并将其放置在页面上不被注意的某个位置。 You could even set
position: relative;
你甚至可以设置
position: relative;
(or absolute/fixed) and give it a z-index: 0;
(或绝对/固定)并给它一个
z-index: 0;
or -1, and then after your axios response, call this.$refs.hiddenButton.click()
making sure that you've set target="_blank"
on the button.或 -1,然后在您的 axios 响应之后,调用
this.$refs.hiddenButton.click()
确保您已在按钮上设置target="_blank"
。
*tip, *小费,
target="_blank"
will open a new tab each time that element is clicked.每次单击该元素时,
target="_blank"
将打开一个新选项卡。
target="blank"
(with no underscore) will open a new tab the first time, and then reuse that tab on each subsequent click. target="blank"
(无下划线)将在第一次打开一个新选项卡,然后在每次后续点击时重复使用该选项卡。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.