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