如何在新选项卡中打开链接以及在当前选项卡中重定向

How to make a link open in new tab as well as redirect in current

本文关键字:选项 链接 重定向 新选项      更新时间:2023-09-26

所以,我需要这样做,如果用户在mysite.com/cat上,他们点击了一些东西,然后在mysitecom/cat选项卡中,他们被重定向到mysite.com/dog,并且在一个新选项卡中打开了一个链接。我试过这样做:<a href="dog.html" target="_self" onclick="window.open('cat.html');">Click</a>哪种有效,但它希望。。。让变得很奇怪

   
<a href="#" target="_self" onclick="RedirectUrl()">Click</a> 
<script>
    
    function RedirectUrl(){    
       window.location.href ="yourUrl";
    }
    <script>

您可以进行

<a href="dog.html" target="_blank" onclick="window.location.href ="dog.html";">Click</a>

您可以只使用html而不使用javascript。试试这个代码:

<a href="dog.html" target="_blank">Click</a>