如何在新标签中打开链接以及在当前重定向 [英] How to make a link open in new tab as well as redirect in current

查看:97
本文介绍了如何在新标签中打开链接以及在当前重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,如果用户使用mysite.com/cat并点击了某些内容,则需要进行此操作,然后在mysite.com/cat选项卡中将它们重定向到mysite.com/dog并打开一个链接在新标签中。我试过这个:< a href =dog.htmltarget =_ selfonclick =window.open('cat.html');>点击< / a> 哪种类型的工作,但它会喜欢...让这一切都很奇怪

解决方案

< a href =#target = _selfonclick =RedirectUrl()>点击< / a> <脚本>函数RedirectUrl(){window.location.href =yourUrl; }< script>


So, I need to make it so if the user is on mysite.com/cat and they click something, then in the mysite.com/cat tab, they are redirected to mysite.com/dog AND a link is opened in a new tab. I tried this: <a href="dog.html" target="_self" onclick="window.open('cat.html');">Click</a> which kind of worked, but it would like... make it all weird

解决方案

   

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

这篇关于如何在新标签中打开链接以及在当前重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆