Javascript Jquery在新选项卡中打开网址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7867329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 03:54:14  来源:igfitidea点击:

Jquery open url in new tab

javascriptjquery

提问by killkrazy

I'm making a personal script to search google in another language and I've got a url that I've passed from a php script. I want to use jquery to open that url in a new tab (only in google chrome).

我正在制作一个个人脚本来用另一种语言搜索谷歌,我有一个从 php 脚本传递过来的 url。我想使用 jquery 在新选项卡中打开该 url(仅在 google chrome 中)。

I tried:

我试过:

  window.open("http://localhost/123", '_blank');

It unfortunately Opens in a new window in google chrome, which is unfortunately the only browser that's light enough to use on my computer. I don't seem to have any success googling it so any advice would be much appreciated.

不幸的是,它在谷歌浏览器的新窗口中打开,不幸的是,这是唯一一款足够轻便的浏览器,可以在我的电脑上使用。我似乎在谷歌上没有任何成功,所以任何建议都将不胜感激。

Thanks Sam

谢谢山姆

EDITED: Sorry if your not meant to edit like this but my new question is (I should probably ask it somewhere else):

编辑:对不起,如果你不打算这样编辑,但我的新问题是(我可能应该在其他地方问):

How to edit google chromes config to open a new tab instead of a window when window.open("href", "_blank") is called?

调用 window.open("href", "_blank") 时,如何编辑谷歌浏览器配置以打开新选项卡而不是窗口?

采纳答案by Adam

You can't directly control this, because it can be configured by the user. You might try "_newtab" which might work for Firefox but really you shouldn't rely on a new tab being opened. The user may have their browser settings set to open a new tab when a popup window is opened or it may show up as a popup. It just all depends on the browser settings.

你不能直接控制它,因为它可以由用户配置。您可以尝试“_newtab”,它可能适用于 Firefox,但实际上您不应该依赖正在打开的新选项卡。用户可以将他们的浏览器设置设置为在打开弹出窗口时打开一个新选项卡,或者它可能显示为一个弹出窗口。这完全取决于浏览器设置。

回答by Irshad Khan

<a href="#" onclick="newTab();">Test</a>

<script>
  function newTab()
   {
     window.open('www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');
   }
</script>

回答by frangly

`$(document).ready(function() {
   $('#NewTab').click(function() {
        $(this).target = "_blank";
        window.open($(this).prop('href'));
        return false;
   });
});`

http://franglyaj.blogspot.in/2012/12/jquery-open-url-in-new-tab-using.html