如何使用 javascript 打开新页面

发布于 2024-11-03 08:42:29 字数 177 浏览 8 评论 0原文

我有设置的代码

window.location.href = [someurl]

,但我想在新选项卡中打开它。无论如何,是否可以

target="_blank"

从 javascript 中包含上述代码?

i have code that sets

window.location.href = [someurl]

but i want to have it open up in a new tab. Is there anyway to have the above code include

target="_blank"

from javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素衣风尘叹 2024-11-10 08:42:29

window.open([someurl], "_blank");

或者因为 _blank 是默认值

window.open([someurl]);

Yes

window.open([someurl], "_blank");

or since _blank is the default

window.open([someurl]);
记忆で 2024-11-10 08:42:29

使用 window.open()

https://developer.mozilla。 org/en/DOM/window.open

window.location.href 只是更改当前窗口的位置。

Use window.open()

https://developer.mozilla.org/en/DOM/window.open

window.location.href just changes the location of the current window.

好久不见√ 2024-11-10 08:42:29

要打开新窗口,您将需要使用另一个现成的 JavaScript 函数。它看起来像这样:

window.open('url to open','window name','attribute1,attribute2') 

该功能允许您打开一个新的浏览器窗口供查看者使用。请注意,所有名称和属性都用逗号而不是空格分隔。以下是里面的所有内容:

  1. 'url to open' 这是您希望在新窗口中显示的页面的网址。

  2. 'window name' 您可以根据自己的喜好命名窗口,以便稍后需要引用该窗口。

  3. 'attribute1,attribute2' 与许多其他事物一样,您可以选择可以调整的属性。

To open a new window, you will need to use yet another ready-made JavaScript function. Here is what it looks like:

window.open('url to open','window name','attribute1,attribute2') 

This is the function that allows you to open a new browser window for the viewer to use. Note that all the names and attributes are separated with a comma rather than spaces. Here is what all the stuff inside is:

  1. 'url to open' This is the web address of the page you wish to appear in the new window.

  2. 'window name' You can name your window whatever you like, in case you need to make a reference to the window later.

  3. 'attribute1,attribute2' As with alot of other things, you have a choice of attributes you can adjust.

就此别过 2024-11-10 08:42:29
window.location.open([someurl], [target="_blank"]);

应该是工作。

window.location.open([someurl], [target="_blank"]);

sould be work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文