admin管理员组文章数量:1418095
I'm using sveltekit goto function to navigate to a page using on:click on a div.
clickHandler: (id: string) => goto(`/app/profile/${id}/settings/general-info`)
How can I specify to open page in a new tab just like using CTRL + Click?
I'm using sveltekit goto function to navigate to a page using on:click on a div.
clickHandler: (id: string) => goto(`/app/profile/${id}/settings/general-info`)
How can I specify to open page in a new tab just like using CTRL + Click?
Share Improve this question asked Oct 25, 2022 at 8:57 Vincent KaraniVincent Karani 711 silver badge3 bronze badges 3-
1
"on:click on a div" is bad. For accessibility, click events should only be attached on interactive elements that are supposed to be clicked, e.g.
button
. – brunnerh Commented Oct 25, 2022 at 9:49 - 1 Does this answer your question? Open a URL in a new tab (and not a new window) – brunnerh Commented Oct 25, 2022 at 9:52
-
2
If an element is supposed to be a link, it should use an
a
tag, that way the user simply can use Ctrl-Click or the right click menu to open the link elsewhere. If you want the link to open in a new tab by default, just specifytarget="_blank"
. – brunnerh Commented Oct 25, 2022 at 10:01
2 Answers
Reset to default 3If you want to manage this from a ts/js file and the code is running client side then you can use window.open instead of goto -
window.open(`/app/profile/${id}/settings/general-info`, "_blank");
you can use a regular <a>
element to create a link and specify target="_blank"
to open it in a new tab.
here is an example of the the code.
<a href="https://svelte.dev" target="_blank">Svelte</a>
a live web environment showing that how it works.
本文标签: javascriptSveltekit goto a new tabStack Overflow
版权声明:本文标题:javascript - Sveltekit goto a new tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745281750a2651461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论