简体   繁体   English

React js - 在鼠标的新选项卡中右键单击打开它打开多个选项卡时,使用 window.open()

[英]React js - On right click open in new tab of mouse it opens multiple tab when, used window.open()

I am using navigation like this in the react js functional component我在反应 js 功能组件中使用这样的导航

trying to work open in a new tab using _blank window open, and also wanted to replicate the same behavior for the right click open in a new tab, I have tried multiple options and combinations as per below尝试使用 _blank window 打开在新选项卡中打开,并且还想为右键单击在新选项卡中打开复制相同的行为,我尝试了多种选项和组合,如下所示

I have tried to add a component-specific event listener as well, might tried bad combinations Thanks in advance!我也尝试添加特定于组件的事件侦听器,可能会尝试错误的组合提前致谢!

 const preventEventBubbling = event => {                  if (event) {             event.preventDefault();             event.stopPropagation();         }     };              const a = document.createElement('a');         a.target = '_blank';         a.href = url;         a.click();         window.addEventListener('contextmenu', event => preventEventBubbling(event));         window.history.back();         return null;          return <iframe title={title} src={url || urls.default} />;
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.14.0/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.14.0/umd/react-dom.production.min.js"></script>

_blank will copy the current behavior and open in a new tab. _blank 将复制当前行为并在新选项卡中打开。

you can try this, Handle right-click and pass this a.target = '_self';你可以试试这个,处理右键单击并传递这个 a.target = '_self'; and for click pass a.target = '_blank'对于点击传递 a.target = '_blank'

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

相关问题 最大化时,Window.open在safari中打开新标签页 - Window.open opens new tab in safari when maximized 带有'noopener'的Window.open打开一个新窗口而不是一个新选项卡 - Window.open with 'noopener' opens a new window instead of a new tab window.open打开一个新选项卡而不是一个新窗口(在chrome中) - window.open opens a new tab instead of a new window (in chrome) Window.open 无缘无故地打开一个空白的新标签 - Window.open opens a blank empty new tab for no reasons window.open始终在Mobile Safari for iPad中打开新选项卡 - window.open always opens new tab in Mobile Safari for iPad window.open 在新的 window 中打开,而不是使用“nofollow/赞助”时的新标签 - window.open opens in new window instead of new tab when using "nofollow/sponsored" 新标签不会打开 window.open html 和 js - New tab won't open window.open html and js 单击带有滚轮的链接会在新选项卡中打开,但在执行右键单击+打开新选项卡时不会打开 - clicking on a link with scroll wheel opens in a new tab but not when right-click + open new tab is performed 右键单击启用“在新标签页/窗口中打开” - Enable “open in new tab/window” in right click 反应路由器 - 在新选项卡中显示 PDF 和 window.open - React Router - show PDF in new tab with window.open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM