使用 JavaScript 在新标签页中打开页面 [英] Open Page in New Tab Using JavaScript
本文介绍了使用 JavaScript 在新标签页中打开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何使用 JavaScript 打开新标签页.我经历了相关的问题,但没有对我有用.当有人单击下面的链接 (example.com) 时,我希望浏览器打开一个新选项卡.我应该添加什么代码以及我应该把代码放在哪里?
我的 html 代码在这里 -
<div class="work-item" data-groups='["all", "webdesign"]' data-url="http://example.com"><figure class="image-container"><img src="images/work/web-one.jpg"/></figure>
解决方案
使用 target 属性指定打开链接文档的位置,
<a href="http://example.com" target="_blank">示例</a>
或在 javascript 中,
function myFunction() {//在新的浏览器窗口中打开链接.window.open("http://example.com");}
I can't figure out how to open a new tab using JavaScript. I went through related questions but nothing worked for me. I want the browser to open a new tab when someone clicks on the link (example.com) below. What code should I add and where should I place that code?
My html code is here -
<section id="work-grid" class="site-inner">
<div class="work-item" data-groups='["all", "webdesign"]' data-url="http://example.com">
<figure class="image-container"><img src="images/work/web-one.jpg" /></figure>
</div>
解决方案
Use the target attribute which specifies where to open the linked document,
<a href="http://example.com" target="_blank">Example</a>
or in javascript,
function myFunction() {
// Open the link in new browser window.
window.open("http://example.com");
}
这篇关于使用 JavaScript 在新标签页中打开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文