【发布时间】:2019-06-07 15:11:03
【问题描述】:
我想创建一个目标属性设置为空白的标签,但实际上并没有将我移动到打开的页面,而是停留在打开它的页面上。
【问题讨论】:
-
这通常是您无法影响的浏览器设置
标签: html hyperlink href target
我想创建一个目标属性设置为空白的标签,但实际上并没有将我移动到打开的页面,而是停留在打开它的页面上。
【问题讨论】:
标签: html hyperlink href target
我希望这会有所帮助。
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style></style>
</head>
<body>
<a href="https://google.com/" trueblank="true" >Click Me</a>
<script>
var links = document.querySelectorAll("a");
links.forEach(function(each) {
each.onclick = function(ev) {
if(this.getAttribute("trueblank") == "true") {
ev.preventDefault();
window.open(this.href);
}
}
});
</script>
</body>
</html>
【讨论】:
按照下面的 JS 代码在当前窗口上打开一个新窗口,用户仍停留在第一页
window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
【讨论】: