重定向到javascript文件中的新选项卡 [英] Redirect to a new tab within javascript file

查看:91
本文介绍了重定向到javascript文件中的新选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码设置为:

top.location.href = [someurl]

但我想在新标签页中打开它。反正有上面的代码包括: target =_ blank

But I want it to open up in a new tab. Is there anyway to have the above code include: target="_blank"?

推荐答案

使用方法 window.open(url,target)打开一个新窗口(这取决于浏览器或用户的设置是否在新窗口或标签):

Use the method window.open(url, target) to open a new window (it depends on the browser or the user's settings whether the URL is opened in a new window or tab):

window.open('http://stackoverflow.com', '_blank');

有关的更多信息window.open(),阅读w3schools上的文档

For more information about window.open(), read the documentation at w3schools.

请注意:大多数浏览器都不允许随意打开新窗口(或标签页),因为它被视为不需要的弹出窗口。

Please note: Randomly opening a new window (or tab) isn't allowed in most browsers, because it is then treated as an "unwanted popup".

这篇关于重定向到javascript文件中的新选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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