简体   繁体   English

如何在vueJs中不点击按钮的情况下在新标签页中打开页面

[英]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.

相关问题 使用 vuejs 打开新的 html 页面选项卡 - open new html page tab using vuejs 单击按钮在浏览器的新选项卡中打开 sapui5 详细信息页面 - open sapui5 detail page in a new tab of the browser on click of a button 强制页面在每次按钮单击时打开一个新选项卡,而不是覆盖 - Force page to open a new tab on each button click instead of overwriting 如何在 vue 3 中单击按钮打开一个新页面? - How to open a new page on button click in vue 3? 如何使用 Playwright 打开新选项卡(例如单击按钮在新选项卡中打开新部分) - How to open the new tab using Playwright (ex. click the button to open the new section in a new tab) 如何在ASP C#上打开新标签页,然后将焦点集中在当前页面上,然后单击按钮将当前页面重定向到另一个页面? - How to open new tab on ASP C# and focus stay on current page then current page redirect to another page on click button? 如何使鼠标“中键”不在页面上的新选项卡中打开? - How to make mouse "Middle Click" not to open in new tab on a page? 单击页面上的另一个按钮时如何打开导航/选项卡? - How to open the nav/tab when I click another button on the page? 在 AngularJS 中单击按钮打开一个新选项卡 - Open a new tab on button click in AngularJS Chrome扩展程序:打开新标签页,然后点击按钮 - Chrome extension: Open new tab and click on button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM