HTML中打开窗口的类型及使用方法
warning:
这篇文章距离上次修改已过446天,其中的内容可能已经有所变动。
在HTML中,可以使用<a>标签的target属性来指定链接打开的窗口类型,或者使用JavaScript中的window.open()方法来打开新窗口。
使用<a>标签的target属性:
<!-- 在当前窗口打开链接 -->
<a href="http://example.com" target="_self">在当前窗口打开</a>
<!-- 在新窗口或标签页中打开链接 -->
<a href="http://example.com" target="_blank">在新窗口打开</a>使用JavaScript中的window.open()方法:
<button onclick="openNewWindow()">点击打开新窗口</button>
<script>
function openNewWindow() {
window.open('http://example.com', '_blank');
}
</script>在这个例子中,当按钮被点击时,会调用openNewWindow函数,该函数使用window.open()方法打开了一个新窗口或新标签页,并导航到http://example.com。
评论已关闭